@@ -13628,6 +13628,123 @@ TEST(python_crossfile_typed_field_calls_issue1277_parallel) {
1362813628 return check_python_crossfile_typed_field_calls_issue1277(true);
1362913629}
1363013630
13631+ /* A base class spelled through a root-binding import (`import pkg.mod.nodes`
13632+ * binds `pkg`; `class X(pkg.mod.nodes.Context)`) is the same class as the
13633+ * from-imported spelling. The Python LSP's inheritance view never resolved the
13634+ * dotted spelling, so a member inherited through it (self.m(), super().m(),
13635+ * super().__init__()) fell to a weak name guess or to nothing. The plain
13636+ * from-import control must keep resolving; the untyped receiver must not. */
13637+ static int check_python_dotted_base_inheritance(bool parallel) {
13638+ const char *nodes = "class Context:\n"
13639+ " def __init__(self, line=-1):\n"
13640+ " self.line = line\n\n"
13641+ " def ctx_only_helper(self):\n"
13642+ " return 1\n\n"
13643+ " def describe(self):\n"
13644+ " return 0\n";
13645+ const char *types = "import pkg.mod.nodes\n"
13646+ "from pkg.mod.nodes import Context\n\n"
13647+ "class DottedType(pkg.mod.nodes.Context):\n"
13648+ " def __init__(self, line=-1):\n"
13649+ " super().__init__(line)\n\n"
13650+ " def run(self):\n"
13651+ " return self.ctx_only_helper()\n\n"
13652+ " def describe(self):\n"
13653+ " return super().describe()\n\n"
13654+ "class PlainType(Context):\n"
13655+ " def run(self):\n"
13656+ " return self.ctx_only_helper()\n\n"
13657+ "def untyped(thing):\n"
13658+ " return thing.ctx_only_helper()\n";
13659+ if (setup_usages_repo("pkg/mod/nodes.py", nodes, "pkg/types.py", types) != 0) {
13660+ FAIL("failed to create temp dir");
13661+ }
13662+ char path[512];
13663+ const char *inits[] = {"pkg/__init__.py", "pkg/mod/__init__.py"};
13664+ for (size_t i = 0; i < sizeof(inits) / sizeof(inits[0]); i++) {
13665+ snprintf(path, sizeof(path), "%s/%s", g_usages_tmpdir, inits[i]);
13666+ if (th_write_file(path, "") != 0) {
13667+ teardown_usages_repo();
13668+ FAIL("failed to write package marker");
13669+ }
13670+ }
13671+ if (parallel) {
13672+ for (int i = 0; i < 50; i++) {
13673+ snprintf(path, sizeof(path), "%s/dotted_pad_%02d.py", g_usages_tmpdir, i);
13674+ if (th_write_file(path, "dotted_padding = 0\n") != 0) {
13675+ teardown_usages_repo();
13676+ FAIL("failed to write parallel-selection fixture");
13677+ }
13678+ }
13679+ }
13680+
13681+ const char *old_workers = getenv("CBM_WORKERS");
13682+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;
13683+ const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");
13684+ char *saved_single = old_single ? strdup(old_single) : NULL;
13685+ if ((old_workers && !saved_workers) || (old_single && !saved_single)) {
13686+ free(saved_workers);
13687+ free(saved_single);
13688+ teardown_usages_repo();
13689+ FAIL("failed to save pipeline environment");
13690+ }
13691+ int pin_workers_rc = parallel ? cbm_setenv("CBM_WORKERS", "4", 1) : 0;
13692+ int pin_single_rc = parallel ? cbm_unsetenv("CBM_INDEX_SINGLE_THREAD") : 0;
13693+
13694+ char db_path[512];
13695+ snprintf(db_path, sizeof(db_path), "%s/test_dotted_base.db", g_usages_tmpdir);
13696+ cbm_pipeline_t *p = pin_workers_rc == 0 && pin_single_rc == 0
13697+ ? cbm_pipeline_new(g_usages_tmpdir, db_path, CBM_MODE_FULL)
13698+ : NULL;
13699+ int run_rc = p ? cbm_pipeline_run(p) : -1;
13700+ cbm_store_t *s = run_rc == 0 ? cbm_store_open_path(db_path) : NULL;
13701+ bool store_opened = s != NULL;
13702+ int dotted_self = -1, dotted_super = -1, dotted_init = -1, plain_self = -1, untyped = -1;
13703+ if (s) {
13704+ const char *project = cbm_pipeline_project_name(p);
13705+ dotted_self = count_lsp_calls(s, project, "pkg.types.DottedType.run",
13706+ "pkg.mod.nodes.Context.ctx_only_helper");
13707+ dotted_super = count_lsp_calls(s, project, "pkg.types.DottedType.describe",
13708+ "pkg.mod.nodes.Context.describe");
13709+ dotted_init = count_lsp_calls(s, project, "pkg.types.DottedType.__init__",
13710+ "pkg.mod.nodes.Context.__init__");
13711+ plain_self = count_lsp_calls(s, project, "pkg.types.PlainType.run",
13712+ "pkg.mod.nodes.Context.ctx_only_helper");
13713+ untyped = count_lsp_calls(s, project, "pkg.types.untyped", "ctx_only_helper");
13714+ cbm_store_close(s);
13715+ }
13716+
13717+ cbm_pipeline_free(p);
13718+ int restore_workers_rc =
13719+ saved_workers ? cbm_setenv("CBM_WORKERS", saved_workers, 1) : cbm_unsetenv("CBM_WORKERS");
13720+ int restore_single_rc = saved_single ? cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1)
13721+ : cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");
13722+ free(saved_workers);
13723+ free(saved_single);
13724+ teardown_usages_repo();
13725+
13726+ ASSERT_EQ(pin_workers_rc, 0);
13727+ ASSERT_EQ(pin_single_rc, 0);
13728+ ASSERT_EQ(restore_workers_rc, 0);
13729+ ASSERT_EQ(restore_single_rc, 0);
13730+ ASSERT_EQ(run_rc, 0);
13731+ ASSERT_TRUE(store_opened);
13732+ ASSERT_EQ(dotted_self, 1); /* self.m() inherited through a dotted base */
13733+ ASSERT_EQ(dotted_super, 1); /* super().m() through a dotted base */
13734+ ASSERT_EQ(dotted_init, 1); /* super().__init__() through a dotted base */
13735+ ASSERT_EQ(plain_self, 1); /* control: from-imported base */
13736+ ASSERT_EQ(untyped, 0); /* control: no receiver type, no LSP edge */
13737+ PASS();
13738+ }
13739+
13740+ TEST(python_dotted_base_inheritance) {
13741+ return check_python_dotted_base_inheritance(false);
13742+ }
13743+
13744+ TEST(python_dotted_base_inheritance_parallel) {
13745+ return check_python_dotted_base_inheritance(true);
13746+ }
13747+
1363113748/* Bind the external-import veto specifically to #1277's typed-field fold.
1363213749 * No base classes or CALLS edges participate: a name-only call fallback
1363313750 * cannot turn this metadata assertion into a false positive. The unguarded
@@ -23778,6 +23895,8 @@ SUITE(pipeline) {
2377823895 RUN_TEST(override_python_through_intermediate_class);
2377923896 RUN_TEST(python_crossfile_typed_field_calls_issue1277);
2378023897 RUN_TEST(python_crossfile_typed_field_calls_issue1277_parallel);
23898+ RUN_TEST(python_dotted_base_inheritance);
23899+ RUN_TEST(python_dotted_base_inheritance_parallel);
2378123900 RUN_TEST(python_typed_field_external_import_stays_unresolved);
2378223901 RUN_TEST(python_typed_field_project_class_resolves);
2378323902 RUN_TEST(usages_creates_edges);
0 commit comments