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.

fix(perl-lsp): split qualified calls on last "::" so multi-level packages resolve

Shane McCarrona100820243a8
diff --git a/internal/cbm/lsp/perl_lsp.c b/internal/cbm/lsp/perl_lsp.c
index bb6c83b56..1beaad88a 100644
--- a/internal/cbm/lsp/perl_lsp.c
+++ b/internal/cbm/lsp/perl_lsp.c
@@ -610,7 +610,14 @@ static void perl_resolve_function_call(PerlLSPContext *ctx, TSNode call) {
return;
const CBMRegisteredFunc *f = NULL;
- char *colons = strstr(name, "::");
+ /* Split on the LAST "::" so multi-level packages keep their full name
+ * (Foo::Bar::sub -> pkg "Foo::Bar", sub "sub"). strstr would stop at the
+ * first "::", yielding pkg "Foo" and a sub name that still contains "::" —
+ * that never resolves, so the call falls through to the bare-name fallback,
+ * which collapses distinct packages' same-named subs onto one winner. */
+ char *colons = NULL;
+ for (char *p = strstr(name, "::"); p; p = strstr(p + 2, "::"))
+ colons = p;
if (colons) {
size_t plen = (size_t)(colons - name);
char *pkg = cbm_arena_strndup(ctx->arena, name, plen);
diff --git a/tests/test_perl_lsp.c b/tests/test_perl_lsp.c
index 9f697597d..50c02c466 100644
--- a/tests/test_perl_lsp.c
+++ b/tests/test_perl_lsp.c
@@ -142,6 +142,31 @@ TEST(perllsp_static_package_call) {
PASS();
}
+/* ── 3b. Multi-level static package call (Foo::Bar::sub()) ──────── */
+/* Regression: the resolver split the qualified name on the FIRST "::", so a
+ * call to Foo::Bar::sub() was mis-parsed as pkg "Foo" / sub "Bar::sub" and
+ * never resolved — falling through to the bare-name fallback, which collapsed
+ * distinct packages' same-named subs onto one winner. Splitting on the LAST
+ * "::" keeps the full package name so perl_lookup_method resolves correctly. */
+TEST(perllsp_static_multilevel_package_call) {
+ const char *src = "package Acme::Widget;\n"
+ "sub render { return 1; }\n"
+ "package main;\n"
+ "sub caller_sub {\n"
+ " Acme::Widget::render();\n"
+ "}\n";
+ CBMFileResult *r = extract_perl(src);
+ ASSERT(r);
+ /* Before the fix this edge was absent (LSP emitted nothing for the
+ * multi-level qualified call). */
+ const CBMResolvedCall *rc =
+ find_resolved_with_strategy(r, "main.caller_sub", "main.render", "perl_static_call");
+ ASSERT(rc != NULL);
+ ASSERT(rc->strategy != NULL);
+ cbm_free_result(r);
+ PASS();
+}
+
/* ── 4. $self method dispatch ($self = shift) ──────────────────── */
TEST(perllsp_self_method) {
@@ -353,6 +378,7 @@ SUITE(perl_lsp) {
RUN_TEST(perllsp_method_via_bless_assignment);
RUN_TEST(perllsp_constructor_class_method);
RUN_TEST(perllsp_static_package_call);
+ RUN_TEST(perllsp_static_multilevel_package_call);
RUN_TEST(perllsp_self_method);
RUN_TEST(perllsp_isa_inheritance);
RUN_TEST(perllsp_use_parent_inheritance);