fix(resolution): scope the #4994 collision match to the 6-hex salt shape
#4997's _collision_aware matched any alphanumeric id suffix, which also matches a class member id (classid_methodname), so a type-annotated field following a method had its reference stolen onto the method in TS/JS/C#. Restrict the sibling match to the actual underscore-collision salt (a 6-char sha1 hex, per _underscore_salted_nid) and add a method-then-field regression test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b227f7200f
commit
92622867d1
2 files changed
+29
-1
No files matched your search
@@ -1888,7 +1888,12 @@ def _apply_symbol_resolution_facts(
|
||||
candidates = [n for n in nodes if n.get("id") == source_id or (
|
||||
isinstance(n.get("id"), str)
|
||||
and n["id"].startswith(source_id + "_")
|
||||
and n["id"][len(source_id) + 1:].isalnum()
|
||||
# Only an underscore-collision salt (`_underscore_salted_nid`, a
|
||||
# 6-char sha1 hex) is a sibling spelling of the same def. A plain
|
||||
# alphanumeric suffix is a child node id (`classid_methodname`), so
|
||||
# matching it would wrongly steal a class member's edge (e.g. a
|
||||
# type-annotated field's reference) onto a preceding method.
|
||||
and re.fullmatch(r"[0-9a-f]{6}", n["id"][len(source_id) + 1:]) is not None
|
||||
and _js_source_path(str(n.get("source_file") or ""), root) == file_path
|
||||
)]
|
||||
if len(candidates) < 2:
|
||||
|
||||
@@ -90,3 +90,26 @@ def test_underscore_sibling_without_collision_is_unchanged(tmp_path):
|
||||
calls = _call_edges(result, labels)
|
||||
assert ("_helper()", "beta()", "L4") in calls
|
||||
assert not any(source == "main()" for source, _, _ in calls)
|
||||
|
||||
|
||||
def test_class_field_reference_stays_on_the_class_not_a_method(tmp_path):
|
||||
"""The #4994 collision fix must not steal a class member's edge. A class whose
|
||||
method is followed by a type-annotated field shares the member-id prefix
|
||||
(`classid_methodname`) with the class, but that is a child node, not an
|
||||
underscore-collision salt - so the field's type reference must stay on the
|
||||
class, not move to the preceding method."""
|
||||
result = _extract(tmp_path, {
|
||||
"widget.ts": "export class Baz {}\n",
|
||||
"foo.ts": (
|
||||
"import { Baz } from './widget';\n"
|
||||
"export class Foo {\n"
|
||||
" render(): number { return 1; }\n"
|
||||
" item: Baz = new Baz();\n"
|
||||
"}\n"
|
||||
),
|
||||
})
|
||||
labels = {n["id"]: n["label"] for n in result["nodes"]}
|
||||
refs = {(labels.get(e["source"]), labels.get(e["target"]))
|
||||
for e in result["edges"] if e.get("relation") == "references"}
|
||||
assert ("Foo", "Baz") in refs
|
||||
assert not any(src and src.endswith("render()") and tgt == "Baz" for src, tgt in refs)
|
||||
Reference in new issue
Block a user