Skip to content

fix(go): fold sibling-file type copies per directory when a same-named package exists - #5414

Closed
PravalVerma wants to merge 1 commit into
Graphify-Labs:v8from
PravalVerma:fix/go-sibling-receiver-same-named-package
Closed

PravalVerma wants to merge 1 commit into
Graphify-Labs:v8from
PravalVerma:fix/go-sibling-receiver-same-named-package

Conversation

@PravalVerma

Copy link
Copy Markdown
Contributor

Follow-up to #5304.

dd11a045 (shipped in 0.9.113) fixed the shape reported in #5304. One closely related shape still drops the call: the receiver type is declared in a sibling file, and another package directory with the same name (alpha/ and other/alpha/, the #5242 layout) also declares that type. No outside reference is needed.

Repro

alpha/types.go        package alpha; type Service struct{}
alpha/impl.go         package alpha; func (s *Service) helper() int {...}; func (s *Service) Run() int { return s.helper() }
other/alpha/types.go  package alpha; type Service struct{}; func (s *Service) Other() int {...}

calls edge for Run → helper:

version result
0.9.101 ['calls']
0.9.112 – 0.9.115 (v8) []
this PR ['calls']

Cause

_merge_go_package_types skipped any id group that spanned more than one directory. So alpha/impl.go kept its own copy of Service, holding both methods. After disambiguation, the package-scoped lookup in _resolve_go_member_calls found two Service nodes in example.com/app/alpha and gave up.

Fix

  • _merge_go_package_types now folds each directory's copies on its own. Same-named directories still stay split from each other, as test_two_packages_sharing_a_directory_name_stay_split requires.
  • The id still collides across directories, so _disambiguate_colliding_node_ids salts it by path. The folded files' method edges are keyed by their own path, which is in no salt (the [Bug]: Go: s.method() edge dropped when the receiver type is in a sibling file and another package names the type (0.9.112) #5304 mechanism). The survivor therefore records the files it absorbed in a transient _go_folded_files. The disambiguation pass consumes it, always pops it, and re-points those edges to the salted survivor.
  • No ids change except that the impl.go fragment disappears. No AST cache bump is needed, because the change is assembly-time only.

Tests

  • test_go_sibling_receiver_with_outside_reference.py: same-named package, with and without an outside reference. It asserts the call, that each package keeps one Service owning its own methods, and that _go_folded_files never reaches the output. A second test covers both packages using the sibling layout.
  • test_go_package_type_fold.py: each of two same-named packages still folds its own files.
  • All 4 fail on v8 and pass with this change.
  • Full suite on Windows / Python 3.14: 11,309 passed and 19 failed. The same 19 fail on unmodified v8 (test_ext_tagged_id_clash, test_pascal_singleton_resolution, two *_memoization tests, one test_multilang), so they are unrelated.
  • Ruff is clean, and the pyright error count on resolution.py is unchanged.

…d package exists

When two package directories share a name (alpha/ and other/alpha/) and both
declare the same type, _merge_go_package_types skipped the whole id group, so
a type declared in one file with methods in a sibling file stayed fragmented.
The package-scoped receiver lookup then saw two candidates and dropped the
same-file s.helper() call. 0.9.101 emitted it; 0.9.112+ did not.

Fold each directory's copies separately. The survivor records the files it
absorbed in a transient _go_folded_files, which
_disambiguate_colliding_node_ids consumes so those files' method edges follow
the salted survivor instead of staying on the dead bare id.

Follow-up to Graphify-Labs#5304.
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @PravalVerma. 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.

@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 · 4 possible issues to check · Merge confidence 5/5

4 possible issues to check · High impact

Go type copies now fold within each source directory, even when another directory has the same package name.

4 possible issues we couldn't confirm

They don't change the score.

Code graph · 4391 functions depend on this change
  • 48 of 613 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 9f5d250 · Full report in the Graphify check

safishamsi added a commit that referenced this pull request Nov 24, 2026
Bump _AST_CACHE_SCHEMA 54 -> 55 for the Python function-parameter call change
(#5418), so cached Python extractions re-run; its walk_calls guard was combined
with the 0.9.119 lambda-parameter guard (both suppress a bare Python call under
a shadowing binding). Harden the #5414 go-fold test with a node-count assert so
it fails without the fix. The wiki/affected/build changes need no schema bump.
0.9.120 changelog and version bump.

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 type declared across sibling files folds per directory even when a same-named package exists elsewhere, so its member calls resolve while the two packages stay distinct. One maintainer tweak: hardened one of the new tests with a node-count assert so it fails without the fix. Thanks @PravalVerma!

@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants