Skip to content

feat(resolve): root an inferred receiver's type name in the file it was written in (slices 1-2) - #331

Merged
Hessesian merged 4 commits into
mainfrom
feat/receiver-origin-slices
Oct 6, 2026
Merged

Hessesian merged 4 commits into
mainfrom
feat/receiver-origin-slices

Conversation

@Hessesian

Copy link
Copy Markdown
Owner

Problem

An inferred receiver (screenFlowInteractor.loadScreenData(refresh = false).text.scenes) carried only the type's bare name. The member lookup then re-resolved that name against the caller's imports, so a type the caller never imports — and any same-named decoy elsewhere (Moneta has 6+ ScreenFlowModel) — turned .text into a Gap although the index holds ScreenFlowModel.text.

Design

Follows the deferred note in docs/superpowers/specs/2026-08-24-qualified-resolution-unification-design.md (per-hop Url becomes a field on ResolvedType) and the CST-unification spec (no bare String on the surface; no cross-domain IR).

  • ResolvedType carries declaring_uri (+ type_path(), resolution_scope()); CstQuery::expr_type stops dropping the origin the inference layer already tracked.
  • SymbolRole::Reference.receiver_type: Option<ResolvedType>; Indexer::find_member_of_type resolves the type root in the origin file (resolve_qualified_in_type_scope) while extension scope stays the caller's. A jar: origin keeps the caller's scope (unchanged behaviour).
  • Slice 2: call hops report the callee's declaring file (DeclaredReturn, Resolver::method_return_type_declared, InferDeps::find_method_return_type_with_origin_for_type). StrategyOutcome carries the origin; the head rule attributes a substituted type-parameter head to the receiver's file, not the member's. Scope functions pass the receiver's origin through.
  • No bare-name / unique-global fallback on a miss; no FQN string encoding.

Tests (red before)

  • field_hop_member_resolves_in_the_file_the_receiver_type_was_written_in (+ origin assertion)
  • call_hop_member_resolves_in_the_file_the_return_type_was_written_in
  • member_of_a_substituted_type_argument_resolves_in_the_receivers_origin
    All use three packages with same-named, same-member decoys and assert the exact resolved file.
    cargo test (2041), clippy -D warnings, fmt clean.

Moneta (resolution-accuracy Moneta/android, 13,325 files)

member recall 92.0% → 92.9%; member Gap 8,844 → 7,383; FilteredCandidate 7,830 → 7,548; text 310→186, scenes 182→127, title 218→176.

Follow-ups (stacked next): slice 2b (foo().bar origin), slice 3 (sibling sites: implicit-receiver member match, references-verify agreement anchor, value_path_anchor).

🤖 Generated with Claude Code

Hessesian and others added 2 commits October 5, 2026 17:02
…as written in (slice 1: field hops)

An inferred receiver (`holder.model.text`) carried only the type's bare name;
the member lookup then re-resolved that name against the CALLER's imports, so a
type the caller never imports (and any same-named decoy elsewhere) broke it.

ResolvedType now carries `declaring_uri` (the per-hop Url the inference layer
already tracked and CstQuery::expr_type dropped; the deferred note in the
qualified-resolution design spec). SymbolRole::Reference holds Option<ResolvedType>
and resolve_identity uses Indexer::find_member_of_type, which resolves the type
root in `declaring_uri` while extension scope stays the caller's
(resolve_qualified_in_type_scope). A `jar:` origin keeps the caller's scope.

Call hops still return the caller's file as origin (slice 2).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A call's return type is spelled in the callee's file (loadScreenData's
`ScreenFlowModel<out IProductScreenTexts>` is imported there, not by the
caller), but call hops reported the caller's file as the origin, so the
slice-1 member lookup still re-resolved the name against the caller.

- resolver: DeclaredReturn / find_method_return_type_declared /
  find_method_return_type_via_supertypes_declared keep the declaring file next
  to the return type; Resolver::method_return_type_declared is the catalogue
  composite (the old method_return_type is now a test-only convenience). A
  supertype substitution is attributed to the subclass file that spelled
  `Base<Int>`.
- InferDeps::find_method_return_type_with_origin_for_type (provided method,
  Indexer overrides; JAR/extension-registry answers report no file and keep the
  caller as origin).
- chain.rs: StrategyOutcome carries the origin; finalize applies the head
  rule — when the declared head is a type parameter the receiver's type
  argument replaced, the name was spelled with the receiver, not the member.
  Scope functions pass the receiver's origin through.
- resolve_field_type_on / resolve_method_return_type_on apply the same head
  rule per hop.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…types wrapper and ReturnType re-export

CI builds tests with RUSTFLAGS=-D warnings; the origin-carrying composite made both unused.

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

Package-qualified types, source extensions, and explicit generic return substitutions can still use the wrong resolution scope.

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

Open (3)
What changed in this PR

Adds declaration-origin tracking to inferred receiver types so chained member resolution uses the file where each type was written.

Changes:

  • Adds origin-aware ResolvedType and method-return inference.
  • Resolves receiver members using declaration scope while retaining caller extension scope.
  • Adds decoy-backed field, call, and generic-substitution tests.
File Description
src/​resolver/​tests.rs Updates anchor calls for separate type and caller scopes.
src/​resolver/​resolve.rs Adds type-scope-aware symbol resolution.
src/​resolver/​qualified.rs Separates type-root and caller extension scopes.
src/​resolver/​mod.rs Updates resolver exports.
src/​resolver/​infer.rs Returns method types with declaration origins.
src/​resolver/​api.rs Exposes origin-aware method return lookup.
src/​indexer/​lookup.rs Adds origin-aware member lookup APIs.
src/​indexer/​infer/​mod.rs Extends ResolvedType with its declaring URI.
src/​indexer/​infer/​expr_type.rs Preserves origins during expression inference.
src/​indexer/​infer/​deps.rs Adds origin-aware inference dependency lookup.
src/​indexer/​infer/​cst_symbol.rs Carries ResolvedType through symbol classification.
src/​indexer/​infer/​cst_symbol_tests.rs Adds cross-package origin regression tests.
src/​indexer/​infer/​chain.rs Propagates origins across fields, calls, and substitutions.
src/​indexer.rs Implements origin-aware method return lookup.
src/​features/​unresolved_symbol_diagnostics.rs Adapts diagnostics to structured receiver types.
src/​features/​references.rs Adapts reference discovery to structured receiver types.
src/​features/​references_verify.rs Adapts receiver verification.
src/​features/​implementation.rs Adapts implementation lookup.

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

Comment thread src/indexer/lookup.rs Outdated
Comment thread src/indexer/infer/chain.rs Outdated
Comment thread src/resolver/infer.rs Outdated
…iew on #331)

- TypeScope (file + optional package) replaces a bare Url for where a qualifier's
  type name resolves; a package-qualified spelling (types.Payload) resolves its
  root through the fully-qualified index and constrains candidates to that package.
  extract_return_type_from_detail now accepts a package-qualified return type
  (it read a lowercase first segment as 'no declared type').
- an explicit call-site type argument that replaces the return head
  (create<Foo>()) was spelled at the call site: origin = caller
- a source extension function's return type reports the selected entry's
  declaring file (find_extension_fn_return_type_declared); JAR files keep the
  caller-scope fallback

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Hessesian
Hessesian merged commit a27f855 into main Oct 6, 2026
4 checks passed
@Hessesian
Hessesian deleted the feat/receiver-origin-slices 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