Skip to content

Commit c06a363

Browse files
fix(registry): drop unique_name CALLS across language boundaries
Python `from unittest.mock import patch` to a unique TSX `patch`. Same language-family guard; JS/TS/TSX stay one family. Fixes #1572 Signed-off-by: rudi193-cmd <rudi193@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com> Signed-off-by: rudi193-cmd <rudi193@gmail.com>
1 parent 11b662f commit c06a363

6 files changed

Lines changed: 146 additions & 27 deletions

File tree

‎src/pipeline/pass_calls.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,10 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
676676
if (!target_node || source_node->id == target_node->id) {
677677
return 0;
678678
}
679-
/* #725: suffix_match is language-agnostic and will attach a Python
680-
* Store.commit() call to a JS function named commit (or a Bash main
681-
* to a Python main). Drop that weak cross-language edge. */
679+
/* #725/#1572: suffix_match and unique_name are language-agnostic and
680+
* will attach a Python Store.commit() call to a JS function named
681+
* commit, or a Python `with patch(...)` to a unique TSX `patch`. Drop
682+
* those weak cross-language edges. */
682683
if (cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
683684
return 0;
684685
}

‎src/pipeline/pass_parallel.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,8 +3024,9 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB
30243024
memory_order_relaxed);
30253025
if (target_node && source_node->id != target_node->id &&
30263026
cbm_suppress_cross_language_suffix_match(lang, target_node->file_path, res.strategy)) {
3027-
/* #725: same guard as pass_calls.c — do not emit a suffix_match
3028-
* CALLS edge across a language boundary. */
3027+
/* #725/#1572: same guard as pass_calls.c — do not emit a
3028+
* suffix_match or unique_name CALLS edge across a language
3029+
* boundary. */
30293030
continue;
30303031
}
30313032
if (!target_node || source_node->id == target_node->id) {

‎src/pipeline/pipeline.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,13 @@ bool cbm_weak_member_unique_name_exempt(bool is_python, bool receiver_is_self_at
320320
bool cbm_suppress_weak_local_binding_call(bool enabled, bool callee_is_locally_bound,
321321
const char *strategy);
322322

323-
/* #725: drop a suffix_match CALLS edge when the caller language and the
324-
* target file's language disagree. unique_name (candidates == 1) is #1572
325-
* and is left alone; same_module / import_map / lsp_* are kept. JS/TS/TSX
326-
* are one family so a .ts helper calling a .tsx function is not dropped.
327-
* Pure; unit-tested in test_registry.c. */
323+
/* #725/#1572: drop a suffix_match or unique_name CALLS edge when the caller
324+
* language and the target file's language disagree. suffix_match is the
325+
* import-distance winner among many same-named symbols (#725);
326+
* unique_name is the candidates==1 case of the same class (#1572).
327+
* same_module / import_map / lsp_* are kept. JS/TS/TSX are one family so a
328+
* .ts helper calling a .tsx function is not dropped. Pure; unit-tested in
329+
* test_registry.c. */
328330
bool cbm_suppress_cross_language_suffix_match(CBMLanguage caller_lang, const char *target_file_path,
329331
const char *strategy);
330332

‎src/pipeline/registry.c‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ bool cbm_suppress_weak_local_binding_call(bool enabled, bool callee_is_locally_b
697697

698698
static bool js_ts_family(CBMLanguage lang) {
699699
return lang == CBM_LANG_JAVASCRIPT || lang == CBM_LANG_TYPESCRIPT || lang == CBM_LANG_TSX ||
700-
lang == CBM_LANG_ARKTS;
700+
lang == CBM_LANG_ARKTS || lang == CBM_LANG_VUE || lang == CBM_LANG_SVELTE ||
701+
lang == CBM_LANG_ASTRO;
701702
}
702703

703704
/* C and C++ are one family for cross-language checks: .h maps to CBM_LANG_CPP
@@ -707,6 +708,10 @@ static bool c_cpp_family(CBMLanguage lang) {
707708
return lang == CBM_LANG_C || lang == CBM_LANG_CPP;
708709
}
709710

711+
static bool jvm_family(CBMLanguage lang) {
712+
return lang == CBM_LANG_JAVA || lang == CBM_LANG_KOTLIN || lang == CBM_LANG_GROOVY;
713+
}
714+
710715
static const char *path_basename(const char *path) {
711716
if (!path || !path[0]) {
712717
return path;
@@ -736,15 +741,12 @@ bool cbm_suppress_cross_language_suffix_match(CBMLanguage caller_lang, const cha
736741
/* Two same-named symbols in different languages: suffix_match picks one
737742
* winner by import-distance and attaches every bare-name call to it
738743
* (#725, Bash/Python main, JS/Python commit). unique_name is the
739-
* candidates==1 case (#1572) and is not this guard — except for a build
740-
* or configuration caller, where even a unique match into another
741-
* language is a collision by construction. */
742-
if (!strategy) {
743-
return false;
744-
}
745-
bool config_caller = build_config_language(caller_lang);
746-
if (strcmp(strategy, "suffix_match") != 0 &&
747-
!(config_caller && strcmp(strategy, "unique_name") == 0)) {
744+
* candidates==1 case of the same class (#1572, Python
745+
* `from unittest.mock import patch` binding to a unique TSX `patch`).
746+
* Build/config callers have no cross-language call semantics, so their
747+
* unique_name collisions are covered by the same guard. */
748+
if (!strategy ||
749+
(strcmp(strategy, "suffix_match") != 0 && strcmp(strategy, "unique_name") != 0)) {
748750
return false;
749751
}
750752
if (caller_lang == CBM_LANG_COUNT || !target_file_path || !target_file_path[0]) {
@@ -760,6 +762,12 @@ bool cbm_suppress_cross_language_suffix_match(CBMLanguage caller_lang, const cha
760762
if (js_ts_family(caller_lang) && js_ts_family(target_lang)) {
761763
return false;
762764
}
765+
if (c_cpp_family(caller_lang) && c_cpp_family(target_lang)) {
766+
return false;
767+
}
768+
if (jvm_family(caller_lang) && jvm_family(target_lang)) {
769+
return false;
770+
}
763771
return true;
764772
}
765773

‎tests/test_pipeline.c‎

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8102,7 +8102,7 @@ TEST(pipeline_python_cross_module_call) {
81028102
/* #725: two same-named symbols across languages must not share CALLS edges.
81038103
* Python Store.commit is the real callee of save(); the JS Editor.commit
81048104
* function is a distinct binding and must have no inbound CALLS from Python.
8105-
* unique_name (candidates==1) is #1572 and is not this claim. */
8105+
* unique_name (candidates==1) is the #1572 pipeline test. */
81068106
TEST(pipeline_cross_language_same_name_does_not_share_calls_issue725) {
81078107
const char *files[] = {"store.py", "app.py", "web/src/pages/Editor.js"};
81088108
const char *contents[] = {"class Store:\n"
@@ -8183,6 +8183,82 @@ TEST(pipeline_cross_language_same_name_does_not_share_calls_issue725) {
81838183
PASS();
81848184
}
81858185

8186+
/* #1572: unique_name (candidates==1) must not bind a Python mock.patch
8187+
* call to the only project symbol named `patch` when that symbol is TSX.
8188+
* The issue fixture is two files: frontend/Panel.tsx and backend/test_thing.py. */
8189+
TEST(pipeline_cross_language_unique_name_does_not_share_calls_issue1572) {
8190+
const char *files[] = {"frontend/Panel.tsx", "backend/test_thing.py"};
8191+
const char *contents[] = {
8192+
"function patch(x: string) {\n"
8193+
" return x;\n"
8194+
"}\n",
8195+
8196+
"from unittest.mock import patch\n"
8197+
"\n"
8198+
"def test_one():\n"
8199+
" with patch(\"os.path.exists\"):\n"
8200+
" pass\n"
8201+
"\n"
8202+
"def test_two():\n"
8203+
" with patch(\"os.path.join\"):\n"
8204+
" pass\n"};
8205+
8206+
if (setup_lang_repo(files, contents, 2) != 0)
8207+
FAIL("tmpdir");
8208+
char db[512];
8209+
snprintf(db, sizeof(db), "%s/test.db", g_lang_tmpdir);
8210+
8211+
cbm_pipeline_t *p = cbm_pipeline_new(g_lang_tmpdir, db, CBM_MODE_FULL);
8212+
ASSERT_NOT_NULL(p);
8213+
ASSERT_EQ(cbm_pipeline_run(p), 0);
8214+
8215+
cbm_store_t *s = cbm_store_open_path(db);
8216+
ASSERT_NOT_NULL(s);
8217+
const char *proj = cbm_pipeline_project_name(p);
8218+
8219+
cbm_node_t *patches = NULL;
8220+
int npatch = 0;
8221+
cbm_store_find_nodes_by_name(s, proj, "patch", &patches, &npatch);
8222+
ASSERT_GT(npatch, 0);
8223+
8224+
int64_t tsx_id = 0;
8225+
for (int i = 0; i < npatch; i++) {
8226+
if (patches[i].file_path && strstr(patches[i].file_path, "Panel.tsx"))
8227+
tsx_id = patches[i].id;
8228+
}
8229+
ASSERT_TRUE(tsx_id != 0);
8230+
8231+
cbm_edge_t *into_tsx = NULL;
8232+
int ntsx = 0;
8233+
cbm_store_find_edges_by_target_type(s, tsx_id, "CALLS", &into_tsx, &ntsx);
8234+
ASSERT_EQ(ntsx, 0);
8235+
8236+
const char *callers[] = {"test_one", "test_two"};
8237+
for (int c = 0; c < 2; c++) {
8238+
cbm_node_t *fns = NULL;
8239+
int nfn = 0;
8240+
cbm_store_find_nodes_by_name(s, proj, callers[c], &fns, &nfn);
8241+
ASSERT_GT(nfn, 0);
8242+
cbm_edge_t *from_fn = NULL;
8243+
int nfrom = 0;
8244+
cbm_store_find_edges_by_source_type(s, fns[0].id, "CALLS", &from_fn, &nfrom);
8245+
for (int i = 0; i < nfrom; i++) {
8246+
ASSERT_TRUE(from_fn[i].target_id != tsx_id);
8247+
}
8248+
if (from_fn)
8249+
cbm_store_free_edges(from_fn, nfrom);
8250+
cbm_store_free_nodes(fns, nfn);
8251+
}
8252+
8253+
if (into_tsx)
8254+
cbm_store_free_edges(into_tsx, ntsx);
8255+
cbm_store_free_nodes(patches, npatch);
8256+
cbm_store_close(s);
8257+
cbm_pipeline_free(p);
8258+
teardown_lang_repo();
8259+
PASS();
8260+
}
8261+
81868262
TEST(pipeline_go_type_classification) {
81878263
/* Port of TestGoTypeClassification */
81888264
const char *files[] = {"types.go"};
@@ -15191,6 +15267,7 @@ SUITE(pipeline) {
1519115267
RUN_TEST(pipeline_swift_cross_package_import);
1519215268
RUN_TEST(pipeline_python_cross_module_call);
1519315269
RUN_TEST(pipeline_cross_language_same_name_does_not_share_calls_issue725);
15270+
RUN_TEST(pipeline_cross_language_unique_name_does_not_share_calls_issue1572);
1519415271
RUN_TEST(pipeline_go_type_classification);
1519515272
RUN_TEST(pipeline_go_grouped_types);
1519615273
RUN_TEST(pipeline_kotlin_project);

‎tests/test_registry.c‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,9 +831,10 @@ TEST(cross_language_config_caller_drops_unique_name_too) {
831831
cbm_suppress_cross_language_suffix_match(CBM_LANG_CMAKE, "src/main.c", "unique_name"));
832832
ASSERT_TRUE(
833833
cbm_suppress_cross_language_suffix_match(CBM_LANG_YAML, "app/models.py", "unique_name"));
834-
/* A code caller's unique_name into another language is still #1572. */
835-
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(
836-
CBM_LANG_PYTHON, "web/src/pages/Editor.js", "unique_name"));
834+
/* A code caller's unique_name into another language is #1572. */
835+
ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON,
836+
"web/src/pages/Editor.js",
837+
"unique_name"));
837838
/* Same-language config targets are untouched. */
838839
ASSERT_FALSE(
839840
cbm_suppress_cross_language_suffix_match(CBM_LANG_MAKEFILE, "lib/Makefile", "unique_name"));
@@ -912,7 +913,7 @@ TEST(registry_tie_break_is_independent_of_registration_order) {
912913

913914
TEST(cross_language_suffix_match_drops_py_vs_js) {
914915
/* #725: two same-named symbols in different languages. suffix_match is the
915-
* strategy that collapses them; unique_name is #1572 and must stay. */
916+
* strategy that collapses them. unique_name is covered by the #1572 test. */
916917
ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "web/src/pages/Editor.js",
917918
"suffix_match"));
918919
ASSERT_TRUE(
@@ -921,8 +922,6 @@ TEST(cross_language_suffix_match_drops_py_vs_js) {
921922
cbm_suppress_cross_language_suffix_match(CBM_LANG_BASH, "cli/main.py", "suffix_match"));
922923
ASSERT_FALSE(
923924
cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "store.py", "suffix_match"));
924-
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(
925-
CBM_LANG_PYTHON, "web/src/pages/Editor.js", "unique_name"));
926925
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(
927926
CBM_LANG_PYTHON, "web/src/pages/Editor.js", "same_module"));
928927
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON,
@@ -987,6 +986,36 @@ TEST(go_bare_ref_never_binds_field) {
987986
PASS();
988987
}
989988

989+
TEST(cross_language_unique_name_drops_py_vs_tsx) {
990+
/* #1572: unique_name is the candidates==1 case of the same class as
991+
* suffix_match. Python `from unittest.mock import patch` must not bind
992+
* to a unique TSX `function patch`. */
993+
ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "frontend/Panel.tsx",
994+
"unique_name"));
995+
ASSERT_TRUE(cbm_suppress_cross_language_suffix_match(CBM_LANG_TSX, "backend/test_thing.py",
996+
"unique_name"));
997+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "backend/test_thing.py",
998+
"unique_name"));
999+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "frontend/Panel.tsx",
1000+
"same_module"));
1001+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "frontend/Panel.tsx",
1002+
"import_map"));
1003+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_PYTHON, "frontend/Panel.tsx",
1004+
"lsp_direct"));
1005+
/* JS/TS/TSX are one family — a .ts caller of a .tsx unique_name stays. */
1006+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_TYPESCRIPT, "frontend/Panel.tsx",
1007+
"unique_name"));
1008+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_JAVASCRIPT, "frontend/Panel.tsx",
1009+
"unique_name"));
1010+
/* C/C++, JVM, and Vue→TS families stay exempt for unique_name. */
1011+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_C, "bpf/probe.h", "unique_name"));
1012+
ASSERT_FALSE(
1013+
cbm_suppress_cross_language_suffix_match(CBM_LANG_GROOVY, "buildSrc/Foo.java", "unique_name"));
1014+
ASSERT_FALSE(cbm_suppress_cross_language_suffix_match(CBM_LANG_VUE, "services/Queue.ts",
1015+
"unique_name"));
1016+
PASS();
1017+
}
1018+
9901019
TEST(dynamic_suppress_drops_weak_method_matches) {
9911020
/* #592/#606/#1276: a member call whose receiver the LSP could not type, that
9921021
* landed via a WEAK short-name strategy, is generic-resolver noise → drop.
@@ -1244,6 +1273,7 @@ SUITE(registry) {
12441273
RUN_TEST(registry_tie_break_is_independent_of_registration_order);
12451274
RUN_TEST(cross_language_ref_drops_go_vs_c);
12461275
RUN_TEST(go_bare_ref_never_binds_field);
1276+
RUN_TEST(cross_language_unique_name_drops_py_vs_tsx);
12471277
RUN_TEST(dynamic_suppress_drops_weak_method_matches);
12481278
RUN_TEST(dynamic_suppress_keeps_high_confidence_and_non_methods);
12491279
RUN_TEST(python_builtin_member_table_matches_builtin_type_methods);

0 commit comments

Comments
 (0)