fix: prevent bare-name node ID collisions across files (fixes #952)#1067
Open
adityachaudhary99 wants to merge 1 commit into
Open
fix: prevent bare-name node ID collisions across files (fixes #952)#1067adityachaudhary99 wants to merge 1 commit into
adityachaudhary99 wants to merge 1 commit into
Conversation
- ensure_named_node now always uses stem-qualified IDs - Same fix for superclass/inheritance resolution in walk() - Same fix for C#, Swift, C++, Java base type fallbacks - Removes bare-name fallback that caused cross-file collisions Previously, _make_id(name) (bare, no stem) was used as fallback when _make_id(stem, name) was not in the per-file seen_ids set, causing identically-named entities in different files to produce colliding IDs. This caused the second entity's node to overwrite the first in the NetworkX graph, losing one entity entirely (safishamsi#952).
ccdf380 to
da0d38a
Compare
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.
Problem
_extract_generic fell back to _make_id(name) (bare name, no stem qualifier) when the stem-qualified ID was not found in the per-file seen_ids. Two files with the same function or class name in different directories would produce identical bare-name IDs -- NetworkX's add_node silently overwrites duplicates, causing one entity to be lost entirely from the graph.
Fix
Removed the bare-name fallback in:
All symbol nodes now use stem-qualified IDs only. The existing _disambiguate_colliding_node_ids post-pass catches any remaining collisions (e.g., a/b/utils.py vs c/b/utils.py where _file_stem alone is not enough).