Skip to content

fix: prevent bare-name node ID collisions across files (fixes #952)#1067

Open
adityachaudhary99 wants to merge 1 commit into
safishamsi:v8from
adityachaudhary99:fix/node-id-collision
Open

fix: prevent bare-name node ID collisions across files (fixes #952)#1067
adityachaudhary99 wants to merge 1 commit into
safishamsi:v8from
adityachaudhary99:fix/node-id-collision

Conversation

@adityachaudhary99
Copy link
Copy Markdown
Contributor

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:

  1. ensure_named_node() — always uses _make_id(stem, name)
  2. Generic superclass resolution in walk()
  3. Swift inheritance specifiers
  4. C# base type resolution
  5. Java _emit_java_parent
  6. C++ inheritance specifiers

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).

- 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).
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.

1 participant