Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

Merge branch 'fix/go-weak-selector-calls' (with main) into fix/go-method-receiver-qn

Martin Vogel71ebbb9a9b54
diff --cc internal/cbm/lsp/go_lsp.c
index 7d9c52621,ba7df163b..cae786e79
--- a/internal/cbm/lsp/go_lsp.c
+++ b/internal/cbm/lsp/go_lsp.c
@@@ -1853,35 -1977,28 +1977,37 @@@ recurse:
// --- Process a single function body ---
- static void process_function(GoLSPContext* ctx, TSNode func_node) {
+ static void process_function(GoLSPContext *ctx, TSNode func_node) {
// Set enclosing function QN
TSNode name_node = ts_node_child_by_field_name(func_node, "name", 4);
- if (ts_node_is_null(name_node)) return;
+ if (ts_node_is_null(name_node))
+ return;
- char* func_name = lsp_node_text(ctx, name_node);
- if (!func_name || !func_name[0]) return;
+ char *func_name = lsp_node_text(ctx, name_node);
+ if (!func_name || !func_name[0])
+ return;
- // Enclosing-function QN must be the BARE package.Func form (no receiver
- // type segment). The textual call events (extract_unified.c) source calls
- // as package_qn.func_name — methods included — and the defs pass creates
- // the graph Method node under the same QN, so any other form breaks the
- // caller-QN join in cbm_pipeline_find_lsp_resolution and the LSP-resolved
- // call silently falls back to the registry short-name resolver. The
- // receiver type still reaches the registry via the def's parent_class /
- // method->receiver_type; it just does not appear in the caller QN.
+ // Enclosing-function QN must be EXACTLY the QN the textual call events
+ // (extract_unified.c compute_func_qn) and the defs pass produce, or the
+ // caller-QN join in cbm_pipeline_find_lsp_resolution breaks and the
+ // LSP-resolved call silently falls back to the registry short-name
+ // resolver. Since #1909 receiver-qualified Go method QNs, that shared
+ // form is package_qn.ReceiverType.method for methods (the ONE-formula
+ // contract: cbm_go_receiver_type_name) and package_qn.func for functions.
ctx->enclosing_func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s", ctx->package_qn, func_name);
+ if (strcmp(ts_node_type(func_node), "method_declaration") == 0) {
+ TSNode recv = ts_node_child_by_field_name(func_node, "receiver", 8);
+ if (!ts_node_is_null(recv)) {
+ char *recv_type = cbm_go_receiver_type_name(ctx->arena, recv, ctx->source);
+ if (recv_type && recv_type[0]) {
+ ctx->enclosing_func_qn = cbm_arena_sprintf(ctx->arena, "%s.%s.%s", ctx->package_qn,
+ recv_type, func_name);
+ }
+ }
+ }
// Push function scope
- CBMScope* saved_scope = ctx->current_scope;
+ CBMScope *saved_scope = ctx->current_scope;
ctx->current_scope = cbm_scope_push(ctx->arena, ctx->current_scope);
// Bind parameters into scope (including variadic)
diff --cc tests/test_pipeline.c
index 9cc757b96,b2ab5fd04..34af3d989
--- a/tests/test_pipeline.c
+++ b/tests/test_pipeline.c
@@@ -5467,57 -5741,123 +5741,174 @@@ TEST(pipeline_python_receiver_suppresse
PASS();
}
+ /* The member guard's one exemption (2026-09-16, v0.10.8 → v0.11.0 A/B on
+ * django/django): a member call whose receiver is an attribute chain rooted at
+ * self/cls, whose callee has exactly ONE definition in the project and is not a
+ * builtin type's own method keeps its unique_name edge —
+ * `self.compiler.apply_converters()` names the only apply_converters there is.
+ * A bare parameter receiver and the builtin-member class the guard was built
+ * for (`parts.extend()` -> a project ListMixin.extend) stay suppressed.
+ * Fewer than 50 files exercises pass_calls.c. */
+ TEST(pipeline_python_receiver_keeps_specific_unique_name_member_call) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_python_uniq_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+
+ write_temp_file(tmp, "compiler.py",
+ "class SQLCompiler:\n"
+ " def apply_converters(self, rows):\n"
+ " return rows\n");
+ write_temp_file(tmp, "mixin.py",
+ "class ListMixin:\n"
+ " def extend(self, other):\n"
+ " return other\n");
+ write_temp_file(tmp, "caller.py",
+ "class RawIterable:\n"
+ " def __init__(self, compiler):\n"
+ " self.compiler = compiler\n"
+ "\n"
+ " def iterate(self):\n"
+ " return self.compiler.apply_converters([])\n"
+ "\n"
+ "\n"
+ "def collect(parts):\n"
+ " parts.extend([1])\n"
+ " return parts\n"
+ "\n"
+ "\n"
+ "def handed_in(compiler):\n"
+ " return compiler.apply_converters([])\n");
+
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/python_uniq.db", tmp);
+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p);
+ ASSERT_EQ(cbm_pipeline_run(p), 0);
+ const char *project = cbm_pipeline_project_name(p);
+
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+
+ /* POSITIVE: the only apply_converters in the project binds through
+ * self.compiler, an object the class owns. */
+ ASSERT_TRUE(cross_file_call_exists(s, project, "iterate", "apply_converters"));
+ /* NEGATIVE: the same unique name through a bare parameter carries no
+ * ownership evidence and stays suppressed (#1276's own shape). */
+ ASSERT_FALSE(cross_file_call_exists(s, project, "handed_in", "apply_converters"));
+ /* NEGATIVE: list.extend on a parameter must not bind ListMixin.extend. */
+ ASSERT_FALSE(cross_file_call_exists(s, project, "collect", "extend"));
+ /* Tripwire against a vacuous run. */
+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "CALLS"), 1);
+
+ cbm_store_close(s);
+ cbm_pipeline_free(p);
+ th_rmtree(tmp);
+ PASS();
+ }
+
+ /* Embedded-script hosts (2026-09-16 probe on JetBrains/Exposed): a member call
+ * inside an HTML <script> body is extracted as JavaScript and carries the JS
+ * receiver flag, but the weak-member guard was gated on the FILE language, so
+ * 4,207 generated Dokka pages bound `localStorage.getItem` to a docs bundle
+ * function through unique_name. HTML (and Vue/Svelte/Astro) join the gate.
+ * POSITIVE tripwire: a bare project call in a plain .js file still resolves. */
+ TEST(pipeline_html_embedded_member_call_stays_unbound) {
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_html_member_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+
+ /* One directory level each: write_temp_file creates a single parent. */
+ write_temp_file(tmp, "scripts/storage.js",
+ "function getItem(key) {\n"
+ " return key;\n"
+ "}\n");
+ write_temp_file(tmp, "scripts/theme.js",
+ "import { getItem } from './storage.js';\n"
+ "\n"
+ "function loadTheme() {\n"
+ " return getItem('theme');\n"
+ "}\n");
+ write_temp_file(tmp, "docs/index.html",
+ "<html><head><script>\n"
+ "var mode = localStorage.getItem('dokka-dark-mode');\n"
+ "</script></head><body></body></html>\n");
+
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/html_member.db", tmp);
+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p);
+ ASSERT_EQ(cbm_pipeline_run(p), 0);
+ const char *project = cbm_pipeline_project_name(p);
+
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+
+ /* NEGATIVE: localStorage's own method must not bind the docs bundle. */
+ ASSERT_FALSE(cross_file_call_exists(s, project, "index", "getItem"));
+ /* POSITIVE: the bare project call in storage.js resolves as before. */
+ ASSERT_TRUE(cross_file_call_exists(s, project, "loadTheme", "getItem"));
+
+ cbm_store_close(s);
+ cbm_pipeline_free(p);
+ th_rmtree(tmp);
+ PASS();
+ }
+
+TEST(pipeline_go_method_caller_keeps_lsp_join) {
+ /* #1909: receiver-qualifying method QNs moves the def/textual-call QN to
+ * package.Type.method — go_lsp's enclosing-function QN must move with it
+ * (the ONE-formula contract), or every LSP resolution sourced from inside
+ * a method body loses its caller join and the edge dies. The callee name
+ * collides across receivers so no short-name fallback can mask the loss. */
+ char tmp[256];
+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_mcall_XXXXXX");
+ if (!cbm_mkdtemp(tmp)) {
+ FAIL("tmpdir");
+ }
+ write_temp_file(tmp, "go.mod", "module example.com/fxmcall\n\ngo 1.22\n");
+ write_temp_file(tmp, "svc/repo.go",
+ "package svc\n"
+ "\n"
+ "type Repo struct {\n"
+ "\tn int\n"
+ "}\n"
+ "\n"
+ "func (r *Repo) Install() int {\n"
+ "\treturn r.helper()\n"
+ "}\n");
+ write_temp_file(tmp, "svc/helper.go",
+ "package svc\n"
+ "\n"
+ "func (r *Repo) helper() int {\n"
+ "\treturn r.n\n"
+ "}\n");
+ write_temp_file(tmp, "other/other.go",
+ "package other\n"
+ "\n"
+ "type Decoy struct{}\n"
+ "\n"
+ "func (d *Decoy) helper() int { return 2 }\n");
+
+ char db_path[512];
+ snprintf(db_path, sizeof(db_path), "%s/go_mcall.db", tmp);
+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
+ ASSERT_NOT_NULL(p);
+ ASSERT_EQ(cbm_pipeline_run(p), 0);
+ const char *project = cbm_pipeline_project_name(p);
+
+ cbm_store_t *s = cbm_store_open_path(db_path);
+ ASSERT_NOT_NULL(s);
+ ASSERT_TRUE(cross_file_call_exists(s, project, "Install", "helper"));
+ cbm_store_close(s);
+ cbm_pipeline_free(p);
+ th_rmtree(tmp);
+ PASS();
+}
+
TEST(pipeline_go_receiver_suppresses_weak_method_edge) {
char tmp[256];
snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_XXXXXX");
@@@ -14738,7 -15434,8 +15485,9 @@@ SUITE(pipeline)
#endif
RUN_TEST(pipeline_tsjs_receiver_suppresses_weak_method_edge);
RUN_TEST(pipeline_python_receiver_suppresses_weak_method_edge);
+ RUN_TEST(pipeline_python_receiver_keeps_specific_unique_name_member_call);
+ RUN_TEST(pipeline_html_embedded_member_call_stays_unbound);
+ RUN_TEST(pipeline_go_method_caller_keeps_lsp_join);
RUN_TEST(pipeline_go_receiver_suppresses_weak_method_edge);
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c);
RUN_TEST(pipeline_go_rw_usage_never_cross_into_c_parallel);