Skip to content

fix(go): resolve shadowed imports as local receivers - #5411

Closed
sdivyanshu90 wants to merge 1 commit into
Graphify-Labs:v8from
sdivyanshu90:fix/go-shadowed-package-receivers
Closed

sdivyanshu90 wants to merge 1 commit into
Graphify-Labs:v8from
sdivyanshu90:fix/go-shadowed-package-receivers

Conversation

@sdivyanshu90

@sdivyanshu90 sdivyanshu90 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #5409

When a local Go receiver shadows an import alias, selectors can produce a false EXTRACTED call into the imported package. Use the visible lexical binding before classifying an import selector and reuse the receiver type resolver for calls and method values. Keep unknown local types from resolving as package calls.

The regression covers a nested binding, restoration of package lookup outside that block, a typed parameter, an unknown parameter and a method value passed as an argument. The AST cache schema bump retires the old call facts.

Validation

  • python -m pytest tests/test_go_import_shadowing.py tests/test_multilang.py -q --tb=short reported 107 passed and one skipped. The regression failed on clean upstream.
  • ruff check . passed.
  • python -m pytest tests -q --tb=short reported 11,723 passed, 222 skipped, one xfailed and one YAML test failure. The YAML failure also occurred on clean upstream. Six Terraform cache failures from the concurrent upstream run did not recur in the final Go run.
  • python -m pyright --pythonpath /home/somu/.venvs/gvenv/bin/python --outputjson matched upstream diagnostics exactly (783 errors and four warnings).
  • python -m graphify update . completed locally.

@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @sdivyanshu90. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 23, 2026
@sdivyanshu90

Copy link
Copy Markdown
Contributor Author

@safishamsi Could you please review this PR?

@graphify-labs graphify-labs Bot 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.

Graphify review View in Graphify

Nothing blocking · 2 possible issues to check · Merge confidence 5/5

2 possible issues to check · High impact

Go selector calls now treat a visible local binding as taking precedence over an import with the same name.

2 possible issues we couldn't confirm
  • A local variable named like an imported package may not stop its calls from being treated as package calls when its type is unknown · graphify/extractors/go.py:897
  • Method values passed as arguments through a shadowed package name are recorded with the wrong receiver · graphify/extractors/go.py:996

They don't change the score.

What this review covered
  • We didn't review 1 file that isn't source code, such as docs, config, images, or generated or third-party code.
  • 3 of 3 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 3896 functions depend on this change
  • 1 function became more coupled. extract() (1337 callers).
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed ae08a2d · Full report in the Graphify check

safishamsi added a commit that referenced this pull request Nov 24, 2026
…batch

Fold the Python-lambda (#5417), Go-import-shadow (#5411) and COBOL GO-TO
(#5423) AST-output changes into one combined _AST_CACHE_SCHEMA bump 53 -> 54,
so cached Python/Go/COBOL extractions re-run. Fix the #5422 regression test's
cwd-fragile `query` assertion to check the queried node (returncode==0 is the
real invariant). 0.9.119 changelog and version bump. The headline is the
#5320 anyio regression fix (graph commands broke on core installs in 0.9.118).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.119 via an authorship-preserving cherry-pick. A local variable that shadows an imported package name now resolves as a local receiver (lexically scoped), and an unknown local fails closed instead of falling back to a package call. Thanks @sdivyanshu90!

@safishamsi safishamsi closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Go selectors on locals that shadow import aliases bind to the wrong package

2 participants