@@ -17535,6 +17535,122 @@ TEST(pipeline_swift_capped_chain_returns_and_metatype_receivers) {
1753517535 PASS();
1753617536}
1753717537
17538+ /* One Swift corpus, sequential and parallel: every (caller, target) pair has
17539+ * the expected CALLS edge count. Callers and targets are "<file stem>.<QN>". */
17540+ typedef struct {
17541+ const char *caller;
17542+ const char *target;
17543+ int expected;
17544+ } swift_call_pair_t;
17545+
17546+ static int swift_call_pairs_case(const char *const *files, int file_count,
17547+ const swift_call_pair_t *pairs, int pair_count) {
17548+ for (int parallel = 0; parallel < 2; parallel++) {
17549+ char tmp[256] = "/tmp/cbm_swift_pairs_XXXXXX";
17550+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));
17551+ for (int i = 0; i < file_count; i++) {
17552+ write_temp_file(tmp, files[i * 2], files[i * 2 + 1]);
17553+ }
17554+ for (int i = 0; parallel && i < 55; i++) {
17555+ char path[64];
17556+ snprintf(path, sizeof(path), "Pad%d.swift", i);
17557+ write_temp_file(tmp, path, "// filler\n");
17558+ }
17559+ XlangEnvSave saved = xlang_env_select(parallel != 0);
17560+ char db[512];
17561+ snprintf(db, sizeof(db), "%s/graph.db", tmp);
17562+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db, CBM_MODE_FULL);
17563+ ASSERT_NOT_NULL(p);
17564+ ASSERT_EQ(cbm_pipeline_run(p), 0);
17565+ cbm_store_t *store = cbm_store_open_path(db);
17566+ ASSERT_NOT_NULL(store);
17567+ const char *project = cbm_pipeline_project_name(p);
17568+ for (int i = 0; i < pair_count; i++) {
17569+ char qn[1024];
17570+ cbm_node_t caller = {0}, target = {0};
17571+ snprintf(qn, sizeof(qn), "%s.%s", project, pairs[i].caller);
17572+ ASSERT_EQ(cbm_store_find_node_by_qn(store, project, qn, &caller), CBM_STORE_OK);
17573+ snprintf(qn, sizeof(qn), "%s.%s", project, pairs[i].target);
17574+ ASSERT_EQ(cbm_store_find_node_by_qn(store, project, qn, &target), CBM_STORE_OK);
17575+ ASSERT_EQ(pipeline_has_calls_edge(store, caller.id, target.id), pairs[i].expected);
17576+ cbm_node_free_fields(&caller);
17577+ cbm_node_free_fields(&target);
17578+ }
17579+ cbm_store_close(store);
17580+ cbm_pipeline_free(p);
17581+ xlang_env_restore(&saved);
17582+ th_rmtree(tmp);
17583+ }
17584+ PASS();
17585+ }
17586+
17587+ /* #2061: `func run<Result>(...) -> Result` returns its own generic parameter,
17588+ * which names no type even where the project declares a `Result`. The bound
17589+ * variable stays unknown and its call keeps the label match, as it did before
17590+ * initializer types were inferred. */
17591+ TEST(pipeline_swift_generic_return_keeps_label_match_issue2061) {
17592+ const char *files[] = {
17593+ "Types.swift",
17594+ "struct Result { func salWait(context: Int) -> Int { 0 } }\n"
17595+ "class Context {\n"
17596+ " func run<Result>(body: () -> Result) -> Result { body() }\n"
17597+ " func make<Element>(body: () -> Element) -> Element { body() }\n"
17598+ "}\n",
17599+ "Calls.swift",
17600+ "class Waiter {\n"
17601+ " func salWait(context: Int) -> Int { 0 }\n"
17602+ " func drain(count: Int) -> Int { 0 }\n"
17603+ "}\n"
17604+ "func generic(_ context: Context) { let result = context.run(body: { Waiter() }); "
17605+ "_ = result.salWait(context: 1) }\n"
17606+ "func element(_ context: Context) { let value = context.make(body: { Waiter() }); "
17607+ "_ = value.drain(count: 1) }\n",
17608+ };
17609+ const swift_call_pair_t pairs[] = {
17610+ {"Calls.generic(_:Context)", "Calls.Waiter.salWait(context:Int)=>Int", 1},
17611+ {"Calls.generic(_:Context)", "Types.Result.salWait(context:Int)=>Int", 0},
17612+ {"Calls.element(_:Context)", "Calls.Waiter.drain(count:Int)=>Int", 1},
17613+ };
17614+ return swift_call_pairs_case(files, 2, pairs, (int)(sizeof(pairs) / sizeof(pairs[0])));
17615+ }
17616+
17617+ /* #2061: `try` / `try await` around a constructor still names the receiver's
17618+ * type, and a subclass receiver reaches its base class and the base class's
17619+ * extension in another file. The Decoy members match the same labels, so a
17620+ * label match alone would land on them. */
17621+ TEST(pipeline_swift_try_initializer_types_receiver_issue2061) {
17622+ const char *files[] = {
17623+ "Types.swift",
17624+ "class Reader {\n"
17625+ " init(path: String) async throws {}\n"
17626+ " func next(count: Int) -> Int { 0 }\n"
17627+ "}\n"
17628+ "class BaseSocket { func close() {} }\n"
17629+ "class ServerSocket: BaseSocket { init(port: Int) throws {} }\n",
17630+ "Vsock.swift",
17631+ "extension BaseSocket { func localVsockAddress() -> Int { 0 } }\n",
17632+ "Calls.swift",
17633+ "class Decoy {\n"
17634+ " func next(count: Int) -> Int { 0 }\n"
17635+ " func localVsockAddress() -> Int { 0 }\n"
17636+ " func close() {}\n"
17637+ "}\n"
17638+ "func awaited() async throws { let reader = try await Reader(path: \"x\"); "
17639+ "_ = reader.next(count: 1) }\n"
17640+ "func vsock() throws { let socket = try ServerSocket(port: 1); "
17641+ "_ = socket.localVsockAddress(); socket.close() }\n",
17642+ };
17643+ const swift_call_pair_t pairs[] = {
17644+ {"Calls.awaited()async", "Types.Reader.next(count:Int)=>Int", 1},
17645+ {"Calls.awaited()async", "Calls.Decoy.next(count:Int)=>Int", 0},
17646+ {"Calls.vsock()", "Vsock.BaseSocket.localVsockAddress()=>Int", 1},
17647+ {"Calls.vsock()", "Calls.Decoy.localVsockAddress()=>Int", 0},
17648+ {"Calls.vsock()", "Types.BaseSocket.close()", 1},
17649+ {"Calls.vsock()", "Calls.Decoy.close()", 0},
17650+ };
17651+ return swift_call_pairs_case(files, 3, pairs, (int)(sizeof(pairs) / sizeof(pairs[0])));
17652+ }
17653+
1753817654TEST(pipeline_swift_return_identity_issue2061) {
1753917655 const char *returns[] = {"pick()=>Int", "pick()=>String"};
1754017656 return swift_declaration_identity_case(
@@ -33663,6 +33779,8 @@ SUITE(pipeline) {
3366333779 RUN_TEST(pipeline_swift_return_identity_issue2061);
3366433780 RUN_TEST(pipeline_swift_receiver_and_chained_closures_issue2061);
3366533781 RUN_TEST(pipeline_swift_capped_chain_returns_and_metatype_receivers);
33782+ RUN_TEST(pipeline_swift_generic_return_keeps_label_match_issue2061);
33783+ RUN_TEST(pipeline_swift_try_initializer_types_receiver_issue2061);
3366633784 RUN_TEST(pipeline_swift_default_before_required_candidates_issue2061);
3366733785 RUN_TEST(pipeline_swift_incompatible_overload_unresolved_issue2061);
3366833786 RUN_TEST(pipeline_swift_incompatible_overload_parallel_fallback_issue2061);
0 commit comments