Skip to content

feat(resolve): origin through top-level calls + sibling-site scope fixes (slices 2b-3) - #332

Merged
Hessesian merged 1 commit into
mainfrom
feat/receiver-origin-slice2b
Oct 6, 2026
Merged

Hessesian merged 1 commit into
mainfrom
feat/receiver-origin-slice2b

Conversation

@Hessesian

Copy link
Copy Markdown
Owner

Stacked on #331 (slices 1-2). Base is that branch; retarget to main once #331 merges.

Slice 2b — top-level calls

  • find_fun_return_type_reachable_declared / InferDeps::find_fun_return_type_reachable_with_origin: a bound top-level function's return type reports the file it was written in (the strategy used to assume the caller's file).
  • A bound top-level function with no declared type gets its body's type, or Unit (Kotlin only), like a member method. A signature with no = after its parameter list is Unit without parsing the declaring file.

Slice 3 — the same bug at sibling sites

  • value_path_anchor resolved a field's type name from the caller's file; it was written in the field's declaring file.
  • references_verify started the supertype walk from the call site for a Reference candidate, a file that declares nothing of the receiver's type, so a genuine subtype reference was rejected as Unrelated. It now starts from the receiver type's declaring file; unresolvable → kept, never rejected.
  • resolve_receiver_callee_in_type_scope splits the type scope from the caller (extension scope stays the caller's); used by find-references' arity query.

Regressions found and fixed while measuring (each with a red test)

  • A declared return type cut off from the 120-char indexed detail (multi-line parameter list) was mistaken for "no type declared" and answered Unit (Moneta safeFlow → startScoring().collectEmit). The full collected signature is now read first.
  • The Unit/body rule leaked to Java methods (FormatUtil.formatAmount → Unit, 400+ bogus typed receivers). It is now Kotlin-only.

Tests (red before)

top_level_call_member_resolves_in_the_file_the_return_type_was_written_in, top_level_expression_body_call_member_resolves_through_the_inferred_return, value_path_field_type_is_resolved_in_the_fields_declaring_file, subtype_call_site_in_a_file_that_declares_neither_type_is_kept, receiver_callee_resolves_the_receiver_type_name_in_its_own_scope, top_level_return_type_declared_after_a_multi_line_parameter_list_is_not_unit, undeclared_return_inference_never_applies_to_a_java_method, signature_declares_an_expression_body_only_for_an_equals_after_the_parameter_list.
cargo test (2049), clippy -D warnings, fmt clean.

Moneta (resolution-accuracy Moneta/android)

main #331 (slices 1-2) this stack
member recall 92.1% 93.0% 93.0%
member CstResolved 192,257 194,405 195,802
member Gap 8,653 7,382 7,267
FilteredCandidate 7,905 7,341 7,437

Run-to-run noise on identical code is about ±0.3pp / ±400 FilteredCandidate (JAR promotion budget).

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Inferred body origins are still lost, and truncated long signatures can be incorrectly classified as returning Unit.

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Extends type-origin tracking through top-level calls and fixes receiver scope selection in resolution and reference verification.

Changes:

  • Preserves declaring-file origins for top-level return types.
  • Resolves field and receiver types in their declaration scope.
  • Adds regression coverage for Kotlin/Java inference and subtype references.
File Description
src/​indexer.rs Implements origin-aware return lookup.
src/​indexer/​infer/​chain.rs Propagates top-level return origins.
src/​indexer/​infer/​deps.rs Adds origin-aware inference API.
src/​indexer/​infer/​cst_symbol_tests.rs Tests top-level call resolution.
src/​features/​references.rs Uses receiver type scope for arity lookup.
src/​features/​references_verify.rs Anchors hierarchy checks to receiver declarations.
src/​resolver/​extension.rs Separates type and extension scopes.
src/​resolver/​infer.rs Infers undeclared Kotlin returns and origins.
src/​resolver/​infer_tests.rs Tests signature and Java behavior.
src/​resolver/​mod.rs Exports the scoped receiver resolver.
src/​resolver/​qualified.rs Resolves field types from declaring files.
src/​resolver/​tests.rs Tests field and receiver scope fixes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/resolver/infer.rs Outdated
Comment thread src/resolver/infer.rs Outdated
Hessesian added a commit that referenced this pull request Oct 6, 2026
… not Unit (review on #332)

- infer_undeclared_return_type returns (type, origin) via infer_expr_type_with_origin:
  fun wrapper() = importedFactory() is Payload spelled where importedFactory was declared
- SignatureBodyKind::Unknown when the collected signature's parameter list never
  closes (collect_signature caps at 15 lines); only a closed list with no = is Unit

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…xes (slices 2b-3)

- top-level call return types report the file they were written in; a bound
  Kotlin function with no declared type gets its body's type (with the body
  expression's origin) or Unit, never from Java, never from a signature the
  15-line collection cut short, never when a declared type was cut from detail
- value_path_anchor, references_verify's supertype walk and the find-references
  arity query resolve a receiver's type name in its own scope

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Hessesian
Hessesian force-pushed the feat/receiver-origin-slice2b branch from abd2aea to a4287ae Compare October 6, 2026 08:52
@Hessesian
Hessesian changed the base branch from feat/receiver-origin-slices to main October 6, 2026 08:52
@Hessesian
Hessesian merged commit d8f2a4e into main Oct 6, 2026
4 checks passed
@Hessesian
Hessesian deleted the feat/receiver-origin-slice2b branch October 6, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants