@@ -7094,6 +7094,132 @@ TEST(pipeline_swift_overloads_parallel_candidates_issue2061) {
70947094 PASS();
70957095}
70967096
7097+ /* #2061: a Swift call matching NONE of a same-named project symbol's
7098+ * overloads must not bind to it (a bare-name match would bind a wrong
7099+ * overload), while the empty-resolution service fallbacks still apply —
7100+ * the contract both resolver paths share (Swift blocks in pass_calls.c
7101+ * and pass_parallel.c). Local `fetch(id:)` cannot take a one-argument
7102+ * unlabeled URL call, so the call stays unresolved and classifies as the
7103+ * global API (#856). */
7104+ TEST(pipeline_swift_incompatible_overload_unresolved_issue2061) {
7105+ char tmp[256];
7106+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_swiftincompat_XXXXXX");
7107+ if (!cbm_mkdtemp(tmp)) {
7108+ FAIL("tmpdir");
7109+ }
7110+
7111+ write_temp_file(tmp, "Sources/Api.swift",
7112+ "func fetch(id: Int) -> Int {\n"
7113+ " return id\n"
7114+ "}\n");
7115+ write_temp_file(tmp, "Sources/Caller.swift",
7116+ "class Caller {\n"
7117+ " func run() -> Int {\n"
7118+ " return fetch(\"https://api.example.com/data\")\n"
7119+ " }\n"
7120+ "}\n");
7121+
7122+ char db_path[512];
7123+ snprintf(db_path, sizeof(db_path), "%s/swiftincompat.db", tmp);
7124+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
7125+ ASSERT_NOT_NULL(p);
7126+ ASSERT_EQ(cbm_pipeline_run(p), 0);
7127+ const char *project = cbm_pipeline_project_name(p);
7128+
7129+ cbm_store_t *s = cbm_store_open_path(db_path);
7130+ ASSERT_NOT_NULL(s);
7131+
7132+ /* The incompatible local definition IS indexed (anti-vacuous guard) ... */
7133+ cbm_node_t *fetches = NULL;
7134+ int fetch_count = 0;
7135+ ASSERT_EQ(cbm_store_find_nodes_by_name(s, project, "fetch", &fetches, &fetch_count),
7136+ CBM_STORE_OK);
7137+ ASSERT_EQ(fetch_count, 1);
7138+ cbm_node_t *runs = NULL;
7139+ int run_count = 0;
7140+ ASSERT_EQ(cbm_store_find_nodes_by_name(s, project, "run", &runs, &run_count), CBM_STORE_OK);
7141+ ASSERT_EQ(run_count, 1);
7142+ /* ... but the call never binds to it ... */
7143+ ASSERT_EQ(pipeline_has_calls_edge(s, runs[0].id, fetches[0].id), 0);
7144+ cbm_store_free_nodes(fetches, fetch_count);
7145+ cbm_store_free_nodes(runs, run_count);
7146+
7147+ /* ... and the URL call still classifies as the global API. */
7148+ ASSERT_EQ(cbm_store_count_edges_by_type(s, project, "HTTP_CALLS"), 1);
7149+
7150+ cbm_store_close(s);
7151+ cbm_pipeline_free(p);
7152+ th_rmtree(tmp);
7153+ PASS();
7154+ }
7155+
7156+ /* The parallel resolver must reach the same verdict for the same fixture
7157+ * (>= 50 files routes calls through resolve_file_calls). */
7158+ TEST(pipeline_swift_incompatible_overload_parallel_fallback_issue2061) {
7159+ char tmp[256];
7160+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_swiftincompat_par_XXXXXX");
7161+ if (!cbm_mkdtemp(tmp)) {
7162+ FAIL("tmpdir");
7163+ }
7164+
7165+ write_temp_file(tmp, "Sources/Api.swift",
7166+ "func fetch(id: Int) -> Int {\n"
7167+ " return id\n"
7168+ "}\n");
7169+ write_temp_file(tmp, "Sources/Caller.swift",
7170+ "class Caller {\n"
7171+ " func run() -> Int {\n"
7172+ " return fetch(\"https://api.example.com/data\")\n"
7173+ " }\n"
7174+ "}\n");
7175+ for (int i = 0; i < 52; i++) {
7176+ char path[64], source[80];
7177+ snprintf(path, sizeof(path), "Sources/Filler%d.swift", i);
7178+ snprintf(source, sizeof(source), "func filler%d() {}\n", i);
7179+ write_temp_file(tmp, path, source);
7180+ }
7181+
7182+ char *previous_workers = getenv("CBM_WORKERS");
7183+ char *saved_workers = previous_workers ? strdup(previous_workers) : NULL;
7184+ cbm_setenv("CBM_WORKERS", "4", 1);
7185+ char db_path[512];
7186+ snprintf(db_path, sizeof(db_path), "%s/swiftincompat.db", tmp);
7187+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);
7188+ int run_result = p ? cbm_pipeline_run(p) : -1;
7189+ if (saved_workers) {
7190+ cbm_setenv("CBM_WORKERS", saved_workers, 1);
7191+ } else {
7192+ cbm_unsetenv("CBM_WORKERS");
7193+ }
7194+ free(saved_workers);
7195+ ASSERT_NOT_NULL(p);
7196+ ASSERT_EQ(run_result, 0);
7197+ const char *project = cbm_pipeline_project_name(p);
7198+
7199+ cbm_store_t *s = cbm_store_open_path(db_path);
7200+ ASSERT_NOT_NULL(s);
7201+
7202+ cbm_node_t *fetches = NULL;
7203+ int fetch_count = 0;
7204+ ASSERT_EQ(cbm_store_find_nodes_by_name(s, project, "fetch", &fetches, &fetch_count),
7205+ CBM_STORE_OK);
7206+ ASSERT_EQ(fetch_count, 1);
7207+ cbm_node_t *runs = NULL;
7208+ int run_count = 0;
7209+ ASSERT_EQ(cbm_store_find_nodes_by_name(s, project, "run", &runs, &run_count), CBM_STORE_OK);
7210+ ASSERT_EQ(run_count, 1);
7211+ ASSERT_EQ(pipeline_has_calls_edge(s, runs[0].id, fetches[0].id), 0);
7212+ cbm_store_free_nodes(fetches, fetch_count);
7213+ cbm_store_free_nodes(runs, run_count);
7214+
7215+ ASSERT_EQ(cbm_store_count_edges_by_type(s, project, "HTTP_CALLS"), 1);
7216+
7217+ cbm_store_close(s);
7218+ cbm_pipeline_free(p);
7219+ th_rmtree(tmp);
7220+ PASS();
7221+ }
7222+
70977223/* Native `fetch()` (#856), parallel path (>= 50 files -> pass_parallel.c's
70987224 * resolve_file_calls). Mirrors pipeline_native_fetch_classified_as_http_calls
70997225 * but forces the parallel resolver, since the empty-resolution fallback is a
@@ -15384,6 +15510,8 @@ SUITE(pipeline) {
1538415510 RUN_TEST(pipeline_swift_http_call_makes_route_issue1892);
1538515511 RUN_TEST(pipeline_swift_overloads_keep_argument_labels_issue2061);
1538615512 RUN_TEST(pipeline_swift_overloads_parallel_candidates_issue2061);
15513+ RUN_TEST(pipeline_swift_incompatible_overload_unresolved_issue2061);
15514+ RUN_TEST(pipeline_swift_incompatible_overload_parallel_fallback_issue2061);
1538715515 RUN_TEST(pipeline_native_fetch_parallel_classified_as_http_calls);
1538815516 RUN_TEST(pipeline_local_fetch_shadow_not_classified_as_http);
1538915517 /* Git history pass */
0 commit comments