Skip to content

fix(resolve): stop binding calls, imports and supertypes to coincidences - #211

Merged
sunerpy merged 1 commit into
mainfrom
fix/tier2-false-edges
Aug 19, 2026
Merged

sunerpy merged 1 commit into
mainfrom
fix/tier2-false-edges

Conversation

@sunerpy

@sunerpy sunerpy commented Aug 19, 2026

Copy link
Copy Markdown
Owner

Tier 2 of the post-v1.5.0 upstream sync. A missing edge makes an agent look further; a false edge makes it confidently wrong. Three shapes produced false ones.

Item 4 — a method resolved to itself (upstream #1496)

Extraction discarded a member-shaped receiver, so this.mailer.send(m) arrived at resolution as the bare name send. With two same-named methods in one file, find_best_match's line-proximity term then scored the enclosing method +20.0 against the real target's +19.7:

send@L4    -> send@L4     ← Outbox.send called ITSELF
forward@L8 -> send@L4     ← and Relay.forward reached the wrong one

Mailer.send@L1 — the true target — got neither edge. The receiver's last segment is now preserved, and across TypeScript, Python, Go, Rust and Swift rather than TypeScript alone, since the plan's own admission was that only TS had been measured.

Item 5 — built-in receivers hijacked project methods (#1566)

The first design placed its refusal after resolve_method_on_type failed. That was dead code: an unimported project class Map beside a built-in produces instance-method 0.9 — the typed path succeeds. The gate now precedes typed resolution and asks whether the inferred type is bound at the call site (same-file declaration, or an import mapping whose local_name matches). No built-in name list is introduced; visibility is the discriminator, so a project class legitimately named Map still resolves.

Inference also now reads a class field's own declaration. enclosing_scope_start_line filters to Function | Method, so a field above a method is unreachable from the backward scan — which left three residual self-edges after item 4 landed:

get@L3 -> get@L3   instance-method 0.7
set@L6 -> set@L6   instance-method 0.7
has@L9 -> has@L9   instance-method 0.7

Teaching inference to see the field beat refusing the fallback, because the field route already reached the correct target — it just guessed. Measured with competing candidates present:

receiver declared today after
local const conn = new Backend() instance-method 0.9 unchanged
field private conn = new Backend() exact-match 0.4 instance-method 0.9

Refusing would have deleted that correct edge; this upgrades it. The lookup reads the field node's own start_line rather than widening the scan window, because the scan takes the nearest match above the call and a class-wide window would prefer a sibling method's const conn = new Wrong().

Item 6 — phantom imports and fabricated supertypes (#1537/#1536)

An imports edge landed on a class property sharing the imported name, and an out-of-repo supertype bound to a local enum member. Both now require a target of compatible kind and locality. Both gates are needed: kind filtering alone merely relocates the false edge onto a legally kinded type_alias, which is why the fixture deliberately keeps an alias to catch a kind-only implementation.

Recursion is untouched

self.run(n - 1) is a genuine self-edge; reference/golden/erlang/edges.json's two remain. A blanket self-exclusion rule would have deleted them and broken golden byte-stability — measured before designing, and the reason that obvious-looking fix was rejected.

Effect on this repository's own index

edge kind before after
implements 132 21 111 removed were all impl Drop for X bound to a C++ enum member; the surviving 21 all target real in-repo traits, interfaces and modules — verified
calls 22045 21733 exact-match −743 against instance-method +432: 432 edges upgraded from a proximity guess to a receiver-typed binding, plus 13 removed self-edges
extends 8 8 see below
contains, imports, instantiates, references byte-identical

extends staying at 8 is load-bearing. An intermediate version regressed it to 12: the new pre-ranking filter collapsed a 2-candidate set to 1, and the single-candidate shortcut skips find_best_match — and with it the cross-language penalty that had correctly sunk those scores, so GDScript extends Node newly bound this repo's Rust struct Node. Fixed by ranking over the filtered set, pinned by its own test. No unit or fixture test caught it — only the whole-repo diff did.

Verification

  • make ci green: 128 suites / 3214 passed / 0 failed (baseline 127 / 3172).
  • git status --porcelain --untracked-files=all reference/ empty; golden instance-method total still 7 (cpp 4, mini 3); erlang's 2 recursion self-edges intact.
  • EXTRACTION_VERSION 5 → 6 exactly once — stored edges change, so an existing index is stale.
  • Eight committed fixtures under crates/codegraph-resolve/tests/fixtures/tier2/, each consumed by an assertion; the acceptance battery fails on main for the stated reason and passes here, with controls (legitimate recursion, an imported class's real calls, an in-repo use) holding throughout.

Declared residue, deliberately not fixed

getMap().get("a") still produces a false edge — item 4 rewrites only member-expression receivers, not the call-expression arm. The non-ESM class-field case persists too (Java/Kotlin have their own inferrers). Both are recorded as persisting-not-regressing rather than silently claimed fixed.

All four upstream issues remain open and PR #1538 is unmerged, so item 6 ports a proposal; items 4 and 5 have no upstream implementation to compare against. The plan cleared five review rounds and ten blockers.

A missing edge makes an agent look further; a false edge makes it confidently
wrong. Three shapes produced false ones.

Extraction discarded a member-shaped receiver, so `this.mailer.send(m)` reached
resolution as the bare name `send`. With two same-named methods in one file the
line-proximity term then scored the enclosing method +20.0 against the real
target's +19.7, and a method resolved to ITSELF while the true callee went
unreferenced. The receiver's last segment is now preserved, across TypeScript,
Python, Go, Rust and Swift rather than TypeScript alone.

Built-in receivers hijacked project methods. The inferred type is now required
to be BOUND at the call site — declared in the same file, or carried by an
import mapping — and the gate sits before typed resolution rather than after
its failure, because the hijack arrives via a typed path that SUCCEEDS. No
built-in name list is introduced; visibility is the discriminator. Inference
additionally reads a class field's own declaration, which the enclosing-scope
scan cannot reach, so a field receiver is typed instead of guessed.

Import and supertype references bound to any local symbol sharing the name: an
`imports` edge landed on a class property, and an out-of-repo supertype on an
enum member. Both now require a target of a compatible kind AND locality,
because kind filtering alone merely relocates the false edge onto a legally
kinded type alias.

Recursion is untouched: `self.run(n - 1)` is a genuine self-edge and the erlang
golden's two remain. On this repo the change removes 111 `impl Drop for X`
edges that had bound to a C++ enum member, leaving 21 that all target real
in-repo traits, interfaces and modules, and upgrades 432 calls from a
proximity guess to a receiver-typed binding.

EXTRACTION_VERSION 5 -> 6: stored edges change, so an existing index is stale.
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.14030% with 32 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/codegraph-resolve/src/import_resolver.rs 94.05% 16 Missing ⚠️
crates/codegraph-resolve/src/name_matcher.rs 97.57% 14 Missing ⚠️
crates/codegraph-extract/src/walker.rs 98.85% 1 Missing ⚠️
crates/codegraph-resolve/src/resolver.rs 98.96% 1 Missing ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #211      +/-   ##
==========================================
+ Coverage   95.22%   95.27%   +0.04%     
==========================================
  Files         137      137              
  Lines       73336    74430    +1094     
==========================================
+ Hits        69836    70911    +1075     
- Misses       3500     3519      +19     
Files with missing lines Coverage Δ
crates/codegraph-resolve/src/types.rs 100.00% <100.00%> (ø)
crates/codegraph-store/src/index_state.rs 83.33% <ø> (ø)
crates/codegraph-extract/src/walker.rs 93.02% <98.85%> (+0.08%) ⬆️
crates/codegraph-resolve/src/resolver.rs 97.06% <98.96%> (+0.06%) ⬆️
crates/codegraph-resolve/src/name_matcher.rs 97.45% <97.57%> (+0.07%) ⬆️
crates/codegraph-resolve/src/import_resolver.rs 96.40% <94.05%> (+0.04%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sunerpy
sunerpy merged commit b9daa8d into main Aug 19, 2026
7 checks passed
@sunerpy
sunerpy deleted the fix/tier2-false-edges branch August 19, 2026 15:59
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.

1 participant