@@ -3026,6 +3026,209 @@ TEST(parallel_csharp_same_name_class_binds_by_namespace) {
30263026 PASS ();
30273027}
30283028
3029+ /* #2120 residual, reported on a real repo: step 8b binds only namespace-
3030+ * qualified TOP-LEVEL types. A qualified `A.B` whose qualifier A is a TYPE
3031+ * (nested-type constructor `new Command.Result(...)`, chained-constructor
3032+ * receiver `new Grain.Handler(dep).Handle(...)`) and a top-level type with NO
3033+ * namespace declaration (global namespace, e.g. a `[Inject]`-consumed service)
3034+ * both fell through to the short-name fallback, where the prefix score against
3035+ * a path-derived QN is 0 for every variant — registration order picked the
3036+ * target. Decoy files are registered FIRST so the old registry-order behavior
3037+ * binds every check to the decoy and the test fails. */
3038+ TEST (parallel_csharp_nested_type_and_global_namespace_binding ) {
3039+ static const char decoy_src [] =
3040+ "namespace Acme.Layouts.Cqrs;\n"
3041+ "public class GrainCommand {\n"
3042+ " public class Handler {\n"
3043+ " public int Handle() => 9;\n"
3044+ " }\n"
3045+ " public class Result {\n"
3046+ " public Result(bool ok) { }\n"
3047+ " public int Code() => 9;\n"
3048+ " }\n"
3049+ "}\n" ;
3050+ static const char partner_src [] =
3051+ "namespace Acme.Partner.Cqrs;\n"
3052+ "public class GrainCommand {\n"
3053+ " public class Handler {\n"
3054+ " private readonly int _v;\n"
3055+ " public Handler(int v) { _v = v; }\n"
3056+ " public int Handle() => _v;\n"
3057+ " }\n"
3058+ " public class Result {\n"
3059+ " public Result(bool ok) { }\n"
3060+ " public int Code() => 1;\n"
3061+ " }\n"
3062+ "}\n" ;
3063+ static const char backoffice_src [] =
3064+ "namespace Acme.BackOffice.Cqrs;\n"
3065+ "public class GrainCommand {\n"
3066+ " public class Result {\n"
3067+ " public Result(bool ok) { }\n"
3068+ " public int Code() => 2;\n"
3069+ " }\n"
3070+ "}\n" ;
3071+ static const char nested_user_src [] =
3072+ "using Acme.Partner.Cqrs;\n"
3073+ "namespace Acme.App;\n"
3074+ "public class NestedUser {\n"
3075+ " public int Run() {\n"
3076+ " var r = new GrainCommand.Result(true);\n"
3077+ " return r.Code();\n"
3078+ " }\n"
3079+ "}\n" ;
3080+ static const char chained_user_src [] =
3081+ "using Acme.Partner.Cqrs;\n"
3082+ "namespace Acme.App;\n"
3083+ "public class ChainedUser {\n"
3084+ " public int Run() {\n"
3085+ " return new GrainCommand.Handler(3).Handle();\n"
3086+ " }\n"
3087+ "}\n" ;
3088+ static const char other_update_src [] =
3089+ "namespace Acme.Other.Web.Services;\n"
3090+ "public class UpdateService {\n"
3091+ " public string Check() => \"other\";\n"
3092+ "}\n" ;
3093+ /* No namespace declaration: the global namespace. */
3094+ static const char global_update_src [] =
3095+ "public class UpdateService {\n"
3096+ " public string Check() => \"global\";\n"
3097+ "}\n" ;
3098+ static const char boot_src [] =
3099+ "namespace Acme.App;\n"
3100+ "public class Boot {\n"
3101+ " public string Boot1() {\n"
3102+ " var u = new UpdateService();\n"
3103+ " return u.Check();\n"
3104+ " }\n"
3105+ "}\n" ;
3106+ /* The lookup-order probe: the SAME simple name resolves through an
3107+ * imported namespace AND exists in the global namespace. C# binds the
3108+ * imported namespace first, so ImportUser.Run2 must hit the Other variant
3109+ * and never the global one — proving the global namespace is appended
3110+ * last in cs_visible_namespaces, not merged as an equal. */
3111+ static const char import_user_src [] =
3112+ "using Acme.Other.Web.Services;\n"
3113+ "namespace Acme.App;\n"
3114+ "public class ImportUser {\n"
3115+ " public string Run2() {\n"
3116+ " var u = new UpdateService();\n"
3117+ " return u.Check();\n"
3118+ " }\n"
3119+ "}\n" ;
3120+ const char * project = "cbm_cs_nested" ;
3121+ static const char * rels [] = {
3122+ "src/Decoy/Layouts.cs" ,
3123+ "src/Decoy/OtherUpdate.cs" ,
3124+ "src/Partner/Cqrs/GrainCommand.cs" ,
3125+ "src/BackOffice/Cqrs/GrainCommand.cs" ,
3126+ "src/Globals/UpdateService.cs" ,
3127+ "src/App/NestedUser.cs" ,
3128+ "src/App/ChainedUser.cs" ,
3129+ "src/App/Boot.cs" ,
3130+ "src/App/ImportUser.cs" ,
3131+ };
3132+ const char * srcs [] = {decoy_src , other_update_src , partner_src ,
3133+ backoffice_src , global_update_src , nested_user_src ,
3134+ chained_user_src , boot_src , import_user_src };
3135+ enum { N_FILES = 9 , N_CHECKS = 10 };
3136+
3137+ char tmpdir [256 ];
3138+ snprintf (tmpdir , sizeof (tmpdir ), "/tmp/cbm_par_cs_nested_XXXXXX" );
3139+ if (!cbm_mkdtemp (tmpdir )) {
3140+ FAIL ("mkdtemp failed" );
3141+ }
3142+ char paths [N_FILES ][512 ];
3143+ cbm_file_info_t files [N_FILES ] = {0 };
3144+ for (int i = 0 ; i < N_FILES ; i ++ ) {
3145+ snprintf (paths [i ], sizeof (paths [i ]), "%s/%s" , tmpdir , rels [i ]);
3146+ if (th_write_file (paths [i ], srcs [i ]) != 0 ) {
3147+ th_rmtree (tmpdir );
3148+ FAIL ("failed to write C# nested-type fixture" );
3149+ }
3150+ files [i ].path = paths [i ];
3151+ files [i ].rel_path = (char * )rels [i ];
3152+ files [i ].language = CBM_LANG_CSHARP ;
3153+ }
3154+
3155+ cbm_gbuf_t * graphs [2 ] = {run_sequential_with_lsp_cross (project , tmpdir , files , N_FILES ), NULL };
3156+ g_harness_cs_registry = true;
3157+ graphs [1 ] = run_parallel (project , tmpdir , files , N_FILES , 2 );
3158+ g_harness_cs_registry = false;
3159+ ASSERT_NOT_NULL (graphs [0 ]);
3160+ ASSERT_NOT_NULL (graphs [1 ]);
3161+
3162+ const char * pf_code = "cbm_cs_nested.src.Partner.Cqrs.GrainCommand.GrainCommand."
3163+ "Result.Code" ;
3164+ const char * pf_handle = "cbm_cs_nested.src.Partner.Cqrs.GrainCommand.GrainCommand."
3165+ "Handler.Handle" ;
3166+ const char * bo_code = "cbm_cs_nested.src.BackOffice.Cqrs.GrainCommand.GrainCommand."
3167+ "Result.Code" ;
3168+ const char * decoy_code = "cbm_cs_nested.src.Decoy.Layouts.GrainCommand.GrainCommand."
3169+ "Result.Code" ;
3170+ const char * decoy_handle = "cbm_cs_nested.src.Decoy.Layouts.GrainCommand.GrainCommand."
3171+ "Handler.Handle" ;
3172+ const char * global_check = "cbm_cs_nested.src.Globals.UpdateService.UpdateService.Check" ;
3173+ const char * other_check = "cbm_cs_nested.src.Decoy.OtherUpdate.UpdateService.Check" ;
3174+ bool ok [2 ][N_CHECKS ];
3175+ bool all = true;
3176+ for (int g = 0 ; g < 2 ; g ++ ) {
3177+ cbm_gbuf_t * gb = graphs [g ];
3178+ ok [g ][0 ] = has_edge_from_callable_to_qn (gb , "NestedUser.Run" , pf_code , "CALLS" );
3179+ ok [g ][1 ] = !has_edge_from_callable_to_qn (gb , "NestedUser.Run" , bo_code , "CALLS" ) &&
3180+ !has_edge_from_callable_to_qn (gb , "NestedUser.Run" , decoy_code , "CALLS" );
3181+ /* The ctor EDGE itself joins through the pipeline's textual carrier and
3182+ * is out of scope here (see PR notes); what must hold is that the
3183+ * nested type RESOLUTION is right, proven by the Code()/Handle() edges
3184+ * above, and that no ctor edge binds to a variant the caller cannot
3185+ * see: neither the BackOffice nor the registry-first decoy. */
3186+ ok [g ][2 ] = !has_edge_from_callable_to_qn (
3187+ gb , "NestedUser.Run" ,
3188+ "cbm_cs_nested.src.BackOffice.Cqrs.GrainCommand.GrainCommand.Result" ,
3189+ "CALLS" ) &&
3190+ !has_edge_from_callable_to_qn (
3191+ gb , "NestedUser.Run" ,
3192+ "cbm_cs_nested.src.BackOffice.Cqrs.GrainCommand.GrainCommand."
3193+ "Result.Result" ,
3194+ "CALLS" );
3195+ ok [g ][3 ] = !has_edge_from_callable_to_qn (gb , "NestedUser.Run" ,
3196+ "cbm_cs_nested.src.Decoy.Layouts.GrainCommand."
3197+ "GrainCommand.Result.Result" ,
3198+ "CALLS" );
3199+ ok [g ][4 ] = has_edge_from_callable_to_qn (gb , "ChainedUser.Run" , pf_handle , "CALLS" );
3200+ ok [g ][5 ] = !has_edge_from_callable_to_qn (gb , "ChainedUser.Run" , decoy_handle , "CALLS" );
3201+ ok [g ][6 ] = has_edge_from_callable_to_qn (gb , "Boot.Boot1" , global_check , "CALLS" );
3202+ ok [g ][7 ] = !has_edge_from_callable_to_qn (gb , "Boot.Boot1" , other_check , "CALLS" );
3203+ ok [g ][8 ] = has_edge_from_callable_to_qn (gb , "ImportUser.Run2" , other_check , "CALLS" );
3204+ ok [g ][9 ] = !has_edge_from_callable_to_qn (gb , "ImportUser.Run2" , global_check , "CALLS" );
3205+ for (int k = 0 ; k < N_CHECKS ; k ++ ) {
3206+ /* The ctor-edge checks 2/3 gate the parallel path only. In the
3207+ * sequential path the `new GrainCommand.Result(true)` edge is
3208+ * still drawn by the textual ctor carrier, not by the resolved
3209+ * type (the out-of-scope carrier join above); on current main it
3210+ * lands on the BackOffice Result already with the nested-type
3211+ * resolution alone. The diagnostic below still prints both. */
3212+ if (g == 0 && (k == 2 || k == 3 ))
3213+ continue ;
3214+ all = all && ok [g ][k ];
3215+ }
3216+ }
3217+ if (!all ) {
3218+ for (int g = 0 ; g < 2 ; g ++ ) {
3219+ printf (" C# nested/global diagnostic %s: nested_code=%d/%d nested_ctor=%d/%d "
3220+ "chained=%d/%d global_ns=%d/%d imported=%d/%d\n" ,
3221+ g == 0 ? "sequential" : "parallel" , ok [g ][0 ], ok [g ][1 ], ok [g ][2 ], ok [g ][3 ],
3222+ ok [g ][4 ], ok [g ][5 ], ok [g ][6 ], ok [g ][7 ], ok [g ][8 ], ok [g ][9 ]);
3223+ }
3224+ }
3225+ cbm_gbuf_free (graphs [0 ]);
3226+ cbm_gbuf_free (graphs [1 ]);
3227+ th_rmtree (tmpdir );
3228+ ASSERT_TRUE (all );
3229+ PASS ();
3230+ }
3231+
30293232/* External Kotlin protocol targets must not borrow a project method merely
30303233 * because the final Class.method segments agree. Raw assertions prove that the
30313234 * iterator/destructuring carriers and their stdlib semantic rows really exist;
@@ -5694,6 +5897,7 @@ SUITE(parallel) {
56945897 RUN_TEST (parallel_typescript_import_namespace_exact_parity );
56955898 RUN_TEST (parallel_tsx_import_namespace_exact_parity );
56965899 RUN_TEST (parallel_csharp_same_name_class_binds_by_namespace );
5900+ RUN_TEST (parallel_csharp_nested_type_and_global_namespace_binding );
56975901 RUN_TEST (parallel_kotlin_external_protocol_does_not_use_project_class_method_tail );
56985902 RUN_TEST (parallel_kotlin_nonbinary_operator_carriers_reach_graph );
56995903 RUN_TEST (parallel_rust_cross_crate_worker_receives_workspace_manifest );
0 commit comments