Skip to content

fix(go): field-chain calls resolve via validated type inference, never bare-name guessing#1316

Merged
colbymchenry merged 1 commit into
mainfrom
fix/1276-go-field-chain
Jul 16, 2026
Merged

fix(go): field-chain calls resolve via validated type inference, never bare-name guessing#1316
colbymchenry merged 1 commit into
mainfrom
fix/1276-go-field-chain

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

Fixes #1276.

target.conn.Exec(...) where conn *sql.DB emitted a bare Exec ref (multi-hop receiver chains were dropped at extraction), and exact-match bound it to the only local Exec — the reporter's unrelated InternalStore interface.

What changed

  • Extraction: Go 2-hop selector chains keep their receiver (target.conn.Exec).
  • Resolution: a dedicated Go field-chain matcher resolves them via two validated inference hops — base's type from the enclosing scope (method receiver / typed param / local, the Local-variable receiver-type inference is C++-only — instance method calls through a local don't resolve in other languages #1108 machinery), then the field's declared type from the struct's own declaration lines (comment-stripped per line; chi's "the tree router" doc comment otherwise donates a phantom type). resolveMethodOnType validates the result.
  • Policy: this path is exclusive for chained Go receivers. External field types (sql.DB, http.Handler) produce no edge — exactly the issue's ask — and package-qualified types are only followed when the package is in-module, so a stdlib interface can never bind a same-named local decoy. No fall-through to bare-name strategies (chained refs were never emitted before, so no existing recall lived there).

Verification

  • Tests: the issue's exact fixture (no InternalStore edges; Repo.Save → Store.Put in-project chain resolves), plus the unexported-type (tree *node) recall case, the doc-comment guard, and the http.Handler-decoy guard.
  • Real-repo before/after on go-chi/chi: node count stable (1,181); +8 correct, validated field-chain edges (mx.tree.FindRoute/InsertRoute/routes, r.MatchOne.Match — all previously unresolvable or wrong); removed edges are the prior bare-name guesses on external receivers (r.Header.GetMux.Get and kin).
  • Full suite: 145 files, 2439 passed.

🤖 Generated with Claude Code

…r bare-name guessing

target.conn.Exec("insert") with `conn *sql.DB` emitted a BARE `Exec`
ref (the receiver chain was dropped for non-identifier receivers), and
exact-match then bound it to the only local `Exec` — an unrelated
interface's method — fabricating an internal dependency (#1276).

Extraction now keeps Go 2-hop selector chains (`base.field.Method`),
and a dedicated matcher resolves them EXCLUSIVELY via two inference
hops: base's type from the enclosing scope (#1108 machinery), field's
declared type from the struct's own declaration lines (comment-
stripped, per-line — chi's "the tree router" doc comment otherwise
donates a phantom type). resolveMethodOnType validates the target.
Package-qualified field types are followed only when the package is
in-module — `handler http.Handler` must not bind a same-named local
decoy. Failure at any hop leaves the ref unresolved: chained Go
receivers never fall through to the bare-name strategies (they were
never emitted before, so no prior recall depends on that path).

chi before/after: node count stable (1,181); 8 correct field-chain
edges gained (mx.tree.FindRoute/InsertRoute/routes, validated,
including the unexported `node` type); the removed edges are the
prior bare-name guesses on external receivers.

Fixes #1276

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Go: external receiver calls resolve to unrelated local interface methods

1 participant