fix(go): field-chain calls resolve via validated type inference, never bare-name guessing#1316
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1276.
target.conn.Exec(...)whereconn *sql.DBemitted a bareExecref (multi-hop receiver chains were dropped at extraction), and exact-match bound it to the only localExec— the reporter's unrelatedInternalStoreinterface.What changed
target.conn.Exec).resolveMethodOnTypevalidates the result.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
InternalStoreedges;Repo.Save → Store.Putin-project chain resolves), plus the unexported-type (tree *node) recall case, the doc-comment guard, and thehttp.Handler-decoy guard.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.Get→Mux.Getand kin).🤖 Generated with Claude Code