@@ -1378,6 +1378,127 @@ TEST(golsp_crossfile_aliased_field_requal) {
13781378 PASS ();
13791379}
13801380
1381+ /* #2033: an identity alias declared in another file of the same package.
1382+ * `type FeatureSet = bitmap` lives in one file, `bitmap.Set` in a second, the
1383+ * call `reqs.Set` in a third, so none of it is in the calling file's AST and
1384+ * only the defs can carry the alias. A defined type (`type Defined bitmap`)
1385+ * must not inherit bitmap's methods. The decoy `other.Set` keeps a name-only
1386+ * match from passing. Both cross-file registries are checked: the per-file
1387+ * one and the prebuilt one shared by the parallel resolve. */
1388+ static CBMLSPDef go_crossfile_alias_defs [] = {
1389+ {.qualified_name = "test.main.bitmap" ,
1390+ .short_name = "bitmap" ,
1391+ .label = "Class" ,
1392+ .def_module_qn = "test.main" },
1393+ {.qualified_name = "test.main.bitmap.Set" ,
1394+ .short_name = "Set" ,
1395+ .label = "Method" ,
1396+ .def_module_qn = "test.main" ,
1397+ .receiver_type = "test.main.bitmap" },
1398+ {.qualified_name = "test.main.FeatureSet" ,
1399+ .short_name = "FeatureSet" ,
1400+ .label = "Type" ,
1401+ .def_module_qn = "test.main" ,
1402+ .alias_target = "bitmap" },
1403+ {.qualified_name = "test.main.Defined" ,
1404+ .short_name = "Defined" ,
1405+ .label = "Class" ,
1406+ .def_module_qn = "test.main" },
1407+ {.qualified_name = "test.main.Framework" ,
1408+ .short_name = "Framework" ,
1409+ .label = "Struct" ,
1410+ .def_module_qn = "test.main" },
1411+ {.qualified_name = "test.main.Framework.NewFeatureSet" ,
1412+ .short_name = "NewFeatureSet" ,
1413+ .label = "Method" ,
1414+ .def_module_qn = "test.main" ,
1415+ .receiver_type = "test.main.Framework" ,
1416+ .return_types = "FeatureSet" },
1417+ {.qualified_name = "test.main.Framework.NewDefined" ,
1418+ .short_name = "NewDefined" ,
1419+ .label = "Method" ,
1420+ .def_module_qn = "test.main" ,
1421+ .receiver_type = "test.main.Framework" ,
1422+ .return_types = "Defined" },
1423+ {.qualified_name = "test.main.other" ,
1424+ .short_name = "other" ,
1425+ .label = "Struct" ,
1426+ .def_module_qn = "test.main" },
1427+ {.qualified_name = "test.main.other.Set" ,
1428+ .short_name = "Set" ,
1429+ .label = "Method" ,
1430+ .def_module_qn = "test.main" ,
1431+ .receiver_type = "test.main.other" },
1432+ };
1433+
1434+ static const char * go_crossfile_alias_source = "package main\n\n"
1435+ "func useAlias(f *Framework) {\n"
1436+ "\treqs := f.NewFeatureSet()\n"
1437+ "\treqs.Set(3)\n}\n\n"
1438+ "func useDefined(f *Framework) {\n"
1439+ "\td := f.NewDefined()\n"
1440+ "\td.Set(3)\n}\n" ;
1441+
1442+ static int go_crossfile_alias_check (const CBMResolvedCallArray * out ) {
1443+ int idx = find_resolved_arr_confident (out , "useAlias" , ".Set" );
1444+ if (idx < 0 || strcmp (out -> items [idx ].callee_qn , "test.main.bitmap.Set" ) != 0 ) {
1445+ printf (" resolved calls (%d):\n" , out -> count );
1446+ for (int i = 0 ; i < out -> count ; i ++ ) {
1447+ const CBMResolvedCall * rc = & out -> items [i ];
1448+ printf (" %s -> %s [%s %.2f]\n" , rc -> caller_qn ? rc -> caller_qn : "(null)" ,
1449+ rc -> callee_qn ? rc -> callee_qn : "(null)" , rc -> strategy ? rc -> strategy : "(null)" ,
1450+ rc -> confidence );
1451+ }
1452+ }
1453+ ASSERT_GTE (idx , 0 );
1454+ ASSERT_STR_EQ (out -> items [idx ].callee_qn , "test.main.bitmap.Set" );
1455+ /* Reached through alias_of, so the emitter reports it the way it reports
1456+ * a same-file alias today (lsp_embed_dispatch): typed, not a name guess. */
1457+ ASSERT_TRUE (strncmp (out -> items [idx ].strategy , "lsp_" , 4 ) == 0 );
1458+ ASSERT_TRUE (strcmp (out -> items [idx ].strategy , "lsp_unresolved" ) != 0 );
1459+ ASSERT_TRUE (out -> items [idx ].confidence >= 0.9f );
1460+ /* A defined type has its own (empty) method set. */
1461+ ASSERT_EQ (find_resolved_arr_confident (out , "useDefined" , "bitmap.Set" ), -1 );
1462+ return 0 ;
1463+ }
1464+
1465+ TEST (golsp_crossfile_type_alias_method ) {
1466+ int n = (int )(sizeof (go_crossfile_alias_defs ) / sizeof (go_crossfile_alias_defs [0 ]));
1467+ CBMArena arena ;
1468+ cbm_arena_init (& arena );
1469+ CBMResolvedCallArray out = {0 };
1470+
1471+ cbm_run_go_lsp_cross (& arena , go_crossfile_alias_source , (int )strlen (go_crossfile_alias_source ),
1472+ "test.main" , go_crossfile_alias_defs , n , NULL , NULL , 0 , NULL , & out );
1473+ if (go_crossfile_alias_check (& out ) != 0 ) {
1474+ cbm_arena_destroy (& arena );
1475+ return 1 ;
1476+ }
1477+
1478+ cbm_arena_destroy (& arena );
1479+ PASS ();
1480+ }
1481+
1482+ TEST (golsp_crossfile_type_alias_method_prebuilt ) {
1483+ int n = (int )(sizeof (go_crossfile_alias_defs ) / sizeof (go_crossfile_alias_defs [0 ]));
1484+ CBMArena arena ;
1485+ cbm_arena_init (& arena );
1486+ CBMResolvedCallArray out = {0 };
1487+
1488+ CBMTypeRegistry * reg = cbm_go_build_cross_registry (& arena , go_crossfile_alias_defs , n );
1489+ ASSERT_NOT_NULL (reg );
1490+ cbm_run_go_lsp_cross_with_registry (& arena , go_crossfile_alias_source ,
1491+ (int )strlen (go_crossfile_alias_source ), "test.main" , reg ,
1492+ NULL , NULL , 0 , NULL , & out );
1493+ if (go_crossfile_alias_check (& out ) != 0 ) {
1494+ cbm_arena_destroy (& arena );
1495+ return 1 ;
1496+ }
1497+
1498+ cbm_arena_destroy (& arena );
1499+ PASS ();
1500+ }
1501+
13811502TEST (golsp_crossfile_local_interface_single_impl ) {
13821503 const char * source =
13831504 "package main\n\n"
@@ -1542,6 +1663,8 @@ SUITE(go_lsp) {
15421663 RUN_TEST (golsp_crossfile_interface_dispatch );
15431664 RUN_TEST (golsp_crossfile_interface_field_chain );
15441665 RUN_TEST (golsp_crossfile_aliased_field_requal );
1666+ RUN_TEST (golsp_crossfile_type_alias_method );
1667+ RUN_TEST (golsp_crossfile_type_alias_method_prebuilt );
15451668 RUN_TEST (golsp_crossfile_map_index );
15461669 RUN_TEST (golsp_crossfile_stdlib_interface );
15471670 RUN_TEST (golsp_crossfile_local_interface_single_impl );
0 commit comments