Skip to content

Commit 613060e

Browse files
committed
address review: drop leftover debug prints, assert imported-over-global order
- remove two temporary DBG fprintf lines left in cs_resolve_object_creation (they fired on every C# object creation) - add ImportUser to the nested/global test: same simple name resolvable through an imported namespace AND present in the global namespace must bind to the imported variant, proving cs_visible_namespaces appends the global namespace last rather than merging it as an equal parallel suite: 76/76 PASS Signed-off-by: Ersin Tarhan <[email protected]>
1 parent d11be54 commit 613060e

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

‎internal/cbm/lsp/cs_lsp.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,18 +2323,14 @@ static void cs_resolve_object_creation(CSLSPContext *ctx, TSNode call) {
23232323
/* `new Foo(...)` adds an implicit constructor CALLS edge: to Foo's ctor
23242324
* Method node when one is indexed, otherwise to the Foo class node. */
23252325
TSNode tnode = ts_node_child_by_field_name(call, "type", 4);
2326-
if (ts_node_is_null(tnode)) {
2327-
fprintf(stderr, "DBG ctor: no type field\n");
2326+
if (ts_node_is_null(tnode))
23282327
return;
2329-
}
23302328
const CBMType *t = cs_parse_type_node(ctx, tnode);
23312329
const char *tqn = NULL;
23322330
if (t && t->kind == CBM_TYPE_NAMED)
23332331
tqn = t->data.named.qualified_name;
23342332
else if (t && t->kind == CBM_TYPE_TEMPLATE)
23352333
tqn = t->data.template_type.template_name;
2336-
fprintf(stderr, "DBG ctor: tqn=%s kind=%d enclosing=%s\n", tqn ? tqn : "(null)",
2337-
t ? (int)t->kind : -1, ctx->enclosing_func_qn ? ctx->enclosing_func_qn : "(null)");
23382334
if (!tqn)
23392335
return;
23402336
/* A C# constructor is extracted as a Method whose short name is the class's

‎tests/test_parallel.c‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,20 @@ TEST(parallel_csharp_nested_type_and_global_namespace_binding) {
27452745
" return u.Check();\n"
27462746
" }\n"
27472747
"}\n";
2748+
/* The lookup-order probe: the SAME simple name resolves through an
2749+
* imported namespace AND exists in the global namespace. C# binds the
2750+
* imported namespace first, so ImportUser.Run2 must hit the Other variant
2751+
* and never the global one — proving the global namespace is appended
2752+
* last in cs_visible_namespaces, not merged as an equal. */
2753+
static const char import_user_src[] =
2754+
"using Acme.Other.Web.Services;\n"
2755+
"namespace Acme.App;\n"
2756+
"public class ImportUser {\n"
2757+
" public string Run2() {\n"
2758+
" var u = new UpdateService();\n"
2759+
" return u.Check();\n"
2760+
" }\n"
2761+
"}\n";
27482762
const char *project = "cbm_cs_nested";
27492763
static const char *rels[] = {
27502764
"src/Decoy/Layouts.cs",
@@ -2755,11 +2769,12 @@ TEST(parallel_csharp_nested_type_and_global_namespace_binding) {
27552769
"src/App/NestedUser.cs",
27562770
"src/App/ChainedUser.cs",
27572771
"src/App/Boot.cs",
2772+
"src/App/ImportUser.cs",
27582773
};
27592774
const char *srcs[] = {decoy_src, other_update_src, partner_src,
27602775
backoffice_src, global_update_src, nested_user_src,
2761-
chained_user_src, boot_src};
2762-
enum { N_FILES = 8, N_CHECKS = 8 };
2776+
chained_user_src, boot_src, import_user_src};
2777+
enum { N_FILES = 9, N_CHECKS = 10 };
27632778

27642779
char tmpdir[256];
27652780
snprintf(tmpdir, sizeof(tmpdir), "/tmp/cbm_par_cs_nested_XXXXXX");
@@ -2827,16 +2842,18 @@ TEST(parallel_csharp_nested_type_and_global_namespace_binding) {
28272842
ok[g][5] = !has_edge_from_callable_to_qn(gb, "ChainedUser.Run", decoy_handle, "CALLS");
28282843
ok[g][6] = has_edge_from_callable_to_qn(gb, "Boot.Boot1", global_check, "CALLS");
28292844
ok[g][7] = !has_edge_from_callable_to_qn(gb, "Boot.Boot1", other_check, "CALLS");
2845+
ok[g][8] = has_edge_from_callable_to_qn(gb, "ImportUser.Run2", other_check, "CALLS");
2846+
ok[g][9] = !has_edge_from_callable_to_qn(gb, "ImportUser.Run2", global_check, "CALLS");
28302847
for (int k = 0; k < N_CHECKS; k++) {
28312848
all = all && ok[g][k];
28322849
}
28332850
}
28342851
if (!all) {
28352852
for (int g = 0; g < 2; g++) {
28362853
printf(" C# nested/global diagnostic %s: nested_code=%d/%d nested_ctor=%d/%d "
2837-
"chained=%d/%d global_ns=%d/%d\n",
2854+
"chained=%d/%d global_ns=%d/%d imported=%d/%d\n",
28382855
g == 0 ? "sequential" : "parallel", ok[g][0], ok[g][1], ok[g][2], ok[g][3],
2839-
ok[g][4], ok[g][5], ok[g][6], ok[g][7]);
2856+
ok[g][4], ok[g][5], ok[g][6], ok[g][7], ok[g][8], ok[g][9]);
28402857
}
28412858
}
28422859
cbm_gbuf_free(graphs[0]);

0 commit comments

Comments
 (0)