Skip to content

fix(resolve): infer expression-body method returns; keep generic receivers typed through field/method hops - #330

Merged
Hessesian merged 3 commits into
mainfrom
fix/expression-body-method-return-type
Oct 5, 2026
Merged

Hessesian merged 3 commits into
mainfrom
fix/expression-body-method-return-type

Conversation

@Hessesian

Copy link
Copy Markdown
Owner

Problem

Moneta's getTexts().title and loadScreenData(..).text.scenes chains missed. Three linked gaps:

  1. find_method_return_type read only a declared : Type, so fun f() = <expr> had no return type. Callers fell through to a bare-name scan that picked an arbitrary same-named function (149 getTexts in the corpus) — a silent wrong target, not just a Gap. The type is now inferred from the expression body behind the existing resolution-cycle guard.
  2. cst_symbol's known-type gate looked the whole inferred string up as a type name, so any generic call-result receiver (Box<out Texts>) lost its receiver_type. It now gates on, and records, the type's own name.
  3. infer_navigation_expr_type returned a member's raw declared type (T) without substituting the receiver's type arguments, and build_type_arg_subst kept out/in projections. Field and method hops now share resolve_field_type_on / resolve_method_return_type_on with the chain strategies; StrExt::strip_variance is the one canonical projection strip.

Tests (each red before the fix)

  • method_return_type_is_inferred_from_an_expression_body (with a decoy getTexts)
  • expression_body_return_inference_terminates_on_a_self_referential_method
  • generic_call_result_receiver_keeps_its_base_type_as_receiver_type
  • property_of_a_type_parameter_resolves_to_the_receivers_type_argument
  • strip_variance_removes_only_a_leading_projection
  • cargo test (2019), clippy -D warnings, fmt clean

Measurement (Moneta, resolution-accuracy, 13,325 files)

Member recall flat at 92.0%, but absolute resolved +14.5k (746.9k → 761.4k); member refs 166k → 209k because many references now carry a receiver type (previously untyped → counted as bare/NameScan). text/title/scenes Gaps stay high for that reason plus a separate root cause (the inferred receiver type loses its origin file) being fixed in the follow-up stack — see the design in docs/superpowers/specs/2026-08-24-qualified-resolution-unification-design.md (deferred declaring_uri note).

Does not fix: bare-name collisions on inferred receiver types, T from firstOrNull, TransformedText.

🤖 Generated with Claude Code

…ivers typed through field/method hops

Three linked gaps behind Moneta's `getTexts().title` / `loadScreenData(..).text.scenes` Gaps:

- find_method_return_type read only a declared `: Type`, so `fun f() = <expr>`
  had no return type and callers fell through to a bare-name scan that picked
  an arbitrary same-named function (a silent wrong target, not just a Gap).
  The type is now inferred from the expression body behind the existing
  resolution-cycle guard.
- cst_symbol's known-type gate looked the WHOLE inferred string up as a type
  name, so any generic call-result receiver (`Box<out Texts>`) lost its
  receiver_type. It now gates on, and records, the type's own name.
- infer_navigation_expr_type returned a field's/method's raw declared type
  (`T`) without substituting the receiver's type arguments, and
  build_type_arg_subst kept `out`/`in` projections. Field and method hops now
  share resolve_field_type_on / resolve_method_return_type_on with the chain
  strategies; StrExt::strip_variance is the one canonical projection strip.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

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

Generic method lookup, projection semantics, qualified-type validation, and implicit Unit returns can currently produce incorrect resolution.

Review effort: Balanced
Findings: 1 High severity · 4 Medium severity

Open (5)
What changed in this PR

Adds expression-body return inference and preserves generic receiver typing through member chains.

Changes:

  • Infers undeclared expression-body method return types with cycle protection.
  • Adds variance stripping and generic type substitution across field/method hops.
  • Retains normalized receiver types during CST symbol classification.
File Description
src/​str_ext.rs Adds variance projection stripping.
src/​str_ext_tests.rs Tests variance stripping.
src/​resolver/​infer.rs Infers expression-body returns.
src/​resolver/​infer_tests.rs Tests inference and cycles.
src/​indexer/​node_ext.rs Reuses variance normalization.
src/​indexer/​infer/​type_subst.rs Normalizes projected type arguments.
src/​indexer/​infer/​expr_type.rs Applies generic-aware member resolution.
src/​indexer/​infer/​cst_symbol.rs Normalizes classified receiver types.
src/​indexer/​infer/​cst_symbol_tests.rs Tests generic receiver chains.
src/​indexer/​infer/​chain.rs Shares substituted field/method resolution.

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

Comment thread src/indexer/infer/type_subst.rs Outdated
Comment thread src/indexer/infer/chain.rs
Comment thread src/indexer/infer/cst_symbol.rs Outdated
Comment thread src/indexer/infer/expr_type.rs Outdated
Comment thread src/resolver/infer.rs Outdated
Hessesian and others added 2 commits October 5, 2026 16:47
…ype gate, Unit returns, lookup key)

- in/star projections bind nothing; out reads as its type (build_type_arg_subst,
  first_type_arg_raw share readable_type_argument)
- the known-type gate validates a qualified path as a whole
  (resolve_type_path_declarations), not by its leaf
- a Kotlin fn with a block body or no body and no declared type returns Unit
- the call branch of infer_navigation_expr_type looks the method up by class name

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Hessesian
Hessesian merged commit c2f4249 into main Oct 5, 2026
4 checks passed
@Hessesian
Hessesian deleted the fix/expression-body-method-return-type branch October 5, 2026 14:58
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