fix(cpp): fail closed on conflicting qualified type identities
A pre-existing same-kind ID collision must not supply positive owner evidence. Add a namespace-collision regression.
Co-Authored-By: OpenAI Codex <noreply@openai.com>
(cherry picked from commit f1716db97c)
This commit is contained in:
1 parent
a1f7d89f1e
commit
9466cac7e5
2 files changed
+21
-2
No files matched your search
@@ -6756,7 +6756,10 @@ def _extract_generic(
|
||||
callable_def_nids.add(class_nid) # a class is callable (constructor)
|
||||
callable_class_nids.add(class_nid) # ...but only via its constructor (#2137)
|
||||
if config.ts_module == "tree_sitter_cpp":
|
||||
cpp_qualified_names[class_nid] = _cpp_qualified_name(node, class_name, source)
|
||||
qualified = _cpp_qualified_name(node, class_name, source)
|
||||
cpp_qualified_names[class_nid] = (
|
||||
qualified if cpp_qualified_names.get(class_nid, qualified) == qualified else ""
|
||||
)
|
||||
# A nested class/object/trait is contained by its ENCLOSING type, not
|
||||
# the file (#2040). parent_class_nid is threaded down the walk for
|
||||
# every language and is always a real class-like node (never a
|
||||
@@ -8203,7 +8206,10 @@ def _extract_generic(
|
||||
add_edge(file_nid, func_nid, "contains", line)
|
||||
callable_def_nids.add(func_nid) # function / method def is callable
|
||||
if config.ts_module == "tree_sitter_cpp" and "::" in func_name:
|
||||
cpp_qualified_names[func_nid] = _cpp_qualified_name(node, func_name, source)
|
||||
qualified = _cpp_qualified_name(node, func_name, source)
|
||||
cpp_qualified_names[func_nid] = (
|
||||
qualified if cpp_qualified_names.get(func_nid, qualified) == qualified else ""
|
||||
)
|
||||
if config.ts_module == "tree_sitter_python":
|
||||
local_bound_names[func_nid] = _python_local_bound_names(node, source)
|
||||
elif config.ts_module in ("tree_sitter_javascript", "tree_sitter_typescript"):
|
||||
|
||||
@@ -62,3 +62,16 @@ def test_ambiguous_included_owner_fails_closed(tmp_path):
|
||||
r = extract([*paths, cpp, other], root=tmp_path, parallel=False, cache_root=tmp_path)
|
||||
caller = next(n["id"] for n in r["nodes"] if n["label"] == "Foo::run()")
|
||||
assert not any(e["source"] == caller and e["relation"] == "calls" for e in r["edges"])
|
||||
|
||||
|
||||
def test_colliding_namespace_types_do_not_manufacture_an_owner(tmp_path):
|
||||
header = tmp_path / "foo.h"
|
||||
header.write_text("namespace Left {class Foo {public: void run(); void say();};}\n"
|
||||
"namespace Right {class Foo {public: void run(); void say();};}", encoding="utf-8")
|
||||
cpp = tmp_path / "main.cpp"
|
||||
cpp.write_text('#include "foo.h"\nvoid Right::Foo::run(){say();}', encoding="utf-8")
|
||||
r = extract([header, cpp], root=tmp_path, parallel=False, cache_root=tmp_path)
|
||||
caller = next(n["id"] for n in r["nodes"] if n["label"] == "Right::Foo::run()")
|
||||
# The existing declaration-id collision is outside this fix. Incomplete
|
||||
# class identity must not turn into positive evidence of an owning type.
|
||||
assert not any(e["relation"] == "method" and e["target"] == caller for e in r["edges"])
|
||||
Reference in new issue
Block a user