Skip to content

Commit 5a3e825

Browse files
committed
fix(registry): gate C# type-keyword receiver check to CBM_LANG_CSHARP
The #2121 fix treated C#'s reserved type keywords (int, string, object, ...) as value roots in receiver_chain_admits without checking the calling file's language. In Python, JS or Go those same spellings are ordinary identifiers, so a lower-case variable named object or string calling a method would fall through to the chain-consistency check and could drop a real CALLS edge outside C#. Add cbm_registry_resolve_lang(..., is_csharp) alongside the existing language-blind cbm_registry_resolve, and thread is_csharp from each file's own language at every call site that resolves a real receiver chain: pass_calls.c and pass_parallel.c (the sequential/parallel CALLS resolvers named in review), plus pass_semantic.c and pass_usages.c so INHERITS/DECORATES/THROWS/RW edges stay gated the same way rather than silently reverting to the pre-#2121 language-blind behavior. The two remaining language-blind callers (pass_calls.c's Python-only Depends scan, pass_lsp_cross.c's base-QN resolve which already excludes C#) are documented in place as never reaching a C# receiver chain. Adds a negative control test asserting a lower-case object/string receiver root still resolves as a value in a non-C# file, pinning the side of the gate a widened keyword list could quietly cost. Signed-off-by: Amir Fathi <[email protected]>
1 parent 36730c7 commit 5a3e825

8 files changed

Lines changed: 257 additions & 99 deletions

File tree

‎src/pipeline/pass_calls.c‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,14 @@ static void free_import_map(const char **keys, const char **vals, int count) {
204204
}
205205
}
206206

207-
/* Handle a route registration call: create Route node + HANDLES edge. */
207+
/* Handle a route registration call: create Route node + HANDLES edge.
208+
* is_csharp is the caller's file-language gate for the #2121 C# receiver-chain
209+
* check (threaded through to the handler-name resolve below); MUST match the
210+
* pass_parallel.c twin (emit_route_registration). */
208211
static void handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
209212
const cbm_gbuf_node_t *source_node, const char *module_qn,
210-
const char **imp_keys, const char **imp_vals, int imp_count) {
213+
const char **imp_keys, const char **imp_vals, int imp_count,
214+
bool is_csharp) {
211215
const char *method = cbm_service_pattern_route_method(call->callee_name);
212216
char route_qn[CBM_ROUTE_QN_SIZE];
213217
char cpath[CBM_SZ_256];
@@ -227,8 +231,9 @@ static void handle_route_registration(cbm_pipeline_ctx_t *ctx, const CBMCall *ca
227231
esc_fa);
228232
cbm_gbuf_insert_edge(ctx->gbuf, source_node->id, route_id, "CALLS", props);
229233
if (call->second_arg_name != NULL && call->second_arg_name[0] != '\0') {
230-
cbm_resolution_t hres = cbm_registry_resolve(ctx->registry, call->second_arg_name,
231-
module_qn, imp_keys, imp_vals, imp_count);
234+
cbm_resolution_t hres = cbm_registry_resolve_lang(ctx->registry, call->second_arg_name,
235+
module_qn, imp_keys, imp_vals, imp_count,
236+
is_csharp);
232237
if (hres.qualified_name != NULL && hres.qualified_name[0] != '\0') {
233238
const cbm_gbuf_node_t *handler = cbm_gbuf_find_by_qn(ctx->gbuf, hres.qualified_name);
234239
if (handler != NULL) {
@@ -418,10 +423,11 @@ static void emit_classified_edge(cbm_pipeline_ctx_t *ctx, const CBMCall *call,
418423
const cbm_gbuf_node_t *source, const cbm_gbuf_node_t *target,
419424
const cbm_resolution_t *res, const char *module_qn,
420425
const char **imp_keys, const char **imp_vals, int imp_count,
421-
bool suppress_plain_calls) {
426+
bool suppress_plain_calls, bool is_csharp) {
422427
cbm_svc_kind_t svc = cbm_service_pattern_match(res->qualified_name);
423428
if (svc == CBM_SVC_ROUTE_REG && call->first_string_arg && call->first_string_arg[0] == '/') {
424-
handle_route_registration(ctx, call, source, module_qn, imp_keys, imp_vals, imp_count);
429+
handle_route_registration(ctx, call, source, module_qn, imp_keys, imp_vals, imp_count,
430+
is_csharp);
425431
return;
426432
}
427433
if (svc == CBM_SVC_HTTP || svc == CBM_SVC_ASYNC) {
@@ -484,6 +490,13 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
484490
return 0;
485491
}
486492

493+
/* #2121: C#'s lower-case type keywords (int, string, ...) are reserved
494+
* words naming a type only in C#; every other language treats them as
495+
* ordinary identifiers. Computed once here and threaded through every
496+
* registry_resolve_lang / handle_route_registration call below; MUST
497+
* match resolve_file_calls's computation in pass_parallel.c exactly. */
498+
bool is_csharp = lang == CBM_LANG_CSHARP;
499+
487500
/* LSP-resolved calls take precedence over registry-textual matching.
488501
* Unique-tail fallbacks are JVM-only (see cbm_pipeline_lsp_allow_tail_match). */
489502
bool allow_tail = cbm_pipeline_lsp_allow_tail_match(lang);
@@ -506,7 +519,7 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
506519
res.strategy = lsp->strategy;
507520
res.candidate_count = 1;
508521
emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys,
509-
imp_vals, imp_count, false);
522+
imp_vals, imp_count, false, is_csharp);
510523
return SKIP_ONE;
511524
}
512525
}
@@ -544,8 +557,8 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
544557
}
545558
}
546559

547-
cbm_resolution_t res = cbm_registry_resolve(ctx->registry, call->callee_name, module_qn,
548-
imp_keys, imp_vals, imp_count);
560+
cbm_resolution_t res = cbm_registry_resolve_lang(ctx->registry, call->callee_name, module_qn,
561+
imp_keys, imp_vals, imp_count, is_csharp);
549562
if (!res.qualified_name || res.qualified_name[0] == '\0') {
550563
/* Resolution is empty when the callee belongs to an EXTERNAL client
551564
* library whose source is not in the indexed tree (e.g. `requests.get`,
@@ -569,7 +582,7 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
569582
if (cbm_service_pattern_route_method(call->callee_name) != NULL && call->first_string_arg &&
570583
call->first_string_arg[0] == '/') {
571584
handle_route_registration(ctx, call, source_node, module_qn, imp_keys, imp_vals,
572-
imp_count);
585+
imp_count, is_csharp);
573586
return SKIP_ONE;
574587
}
575588
cbm_svc_kind_t esvc = cbm_service_pattern_match(call->callee_name);
@@ -683,7 +696,7 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call,
683696
return 0;
684697
}
685698
emit_classified_edge(ctx, call, source_node, target_node, &res, module_qn, imp_keys, imp_vals,
686-
imp_count, drop_plain_call);
699+
imp_count, drop_plain_call, is_csharp);
687700
return SKIP_ONE;
688701
}
689702

@@ -920,6 +933,11 @@ static int scan_depends_in_sig(cbm_pipeline_ctx_t *ctx, const cbm_regex_t *re, c
920933
}
921934
memcpy(func_ref, scan + match[SKIP_ONE].rm_so, (size_t)ref_len);
922935
func_ref[ref_len] = '\0';
936+
/* Plain cbm_registry_resolve (is_csharp=false) is correct here, not a
937+
* gap: cbm_pipeline_pass_fastapi_depends only calls this for files
938+
* where files[i].language == CBM_LANG_PYTHON (see its own guard), so
939+
* func_ref can never come from a C# file and the #2121 keyword gate
940+
* never applies. */
923941
cbm_resolution_t res = cbm_registry_resolve(ctx->registry, func_ref, module_qn, ik, iv, ic);
924942
if (res.qualified_name && res.qualified_name[0] != '\0') {
925943
const cbm_gbuf_node_t *sn = cbm_gbuf_find_by_qn(ctx->gbuf, def->qualified_name);

‎src/pipeline/pass_lsp_cross.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,12 @@ static bool pxc_base_strategy_is_weak(const char *strategy) {
224224
* pass_semantic.c::resolve_as_class — same registry, same type-like veto —
225225
* then additionally rejects weak short-name strategies (see above).
226226
* Returns NULL when the base is not a confidently-known project type;
227-
* stdlib and third-party bases land here and keep their raw spelling. */
227+
* stdlib and third-party bases land here and keep their raw spelling.
228+
* Plain cbm_registry_resolve (is_csharp=false) is correct here, not a gap:
229+
* the only caller (pxc_join_base_qns, via pxc_build_lsp_def) is gated on
230+
* pxc_lang_resolves_base_qns(lang), whose default case explicitly excludes
231+
* C# ("Go / JVM / C# / C++ / Rust registrars qualify their own embedded
232+
* types already"), so `raw` can never come from a C# file's base_classes. */
228233
static const char *pxc_resolve_base_qn(const cbm_registry_t *reg, const char *raw,
229234
const char *module_qn, const char **imp_keys,
230235
const char **imp_vals, int imp_count) {

0 commit comments

Comments
 (0)