@@ -485,6 +485,7 @@ typedef struct {
485485 cbm_resolution_t res ;
486486 size_t scope_len ; /* raw and Python-scoped requests may share one file cache */
487487 bool skip_members ; /* a C call and a C reference to the same name share it too */
488+ bool cs_keywords ; /* a C# call and a C# reference to the same name share it too */
488489} resolve_cache_entry_t ;
489490
490491static CBM_TLS CBMHashTable * _resolve_cache = NULL ;
@@ -2384,6 +2385,26 @@ static const char *qualified_suffix_match(const qn_array_t *arr, const char *cal
23842385 return match ;
23852386}
23862387
2388+ /* True when the first segment of the dotted chain `dotted` is one of C#'s
2389+ * built-in type keywords (int, string, bool, ...; nint and nuint since C# 9).
2390+ * Closed list: these words are grammar, not a naming heuristic. `dynamic` is
2391+ * not on it: the type has no static members, so `dynamic.X` is a variable
2392+ * named `dynamic` and stays an ordinary lower-case value root. */
2393+ static bool cs_type_keyword_root (const char * dotted ) {
2394+ static const char * const keywords [] = {
2395+ "bool" , "byte" , "char" , "decimal" , "double" , "float" , "int" , "long" , "nint" ,
2396+ "nuint" , "object" , "sbyte" , "short" , "string" , "uint" , "ulong" , "ushort" , "void" ,
2397+ };
2398+ const char * dot = strchr (dotted , '.' );
2399+ size_t len = dot ? (size_t )(dot - dotted ) : strlen (dotted );
2400+ for (size_t i = 0 ; i < sizeof (keywords ) / sizeof (keywords [0 ]); i ++ ) {
2401+ if (strlen (keywords [i ]) == len && strncmp (dotted , keywords [i ], len ) == 0 ) {
2402+ return true;
2403+ }
2404+ }
2405+ return false;
2406+ }
2407+
23872408/* A dotted callee whose FIRST segment starts upper-case names a type — URLSession,
23882409 * Calendar, JSONEncoder. That receiver chain is evidence the bare-name scorers
23892410 * throw away, and throwing it away binds Foundation's URLSession.shared.data to
@@ -2397,9 +2418,17 @@ static const char *qualified_suffix_match(const qn_array_t *arr, const char *cal
23972418 * show, so the chain proves nothing there and the call passes through
23982419 * unchanged. A callee with no separator passes through as well.
23992420 *
2400- * Language agnostic by design: the registry holds no language, and every
2401- * language that writes receiver chains gains the same protection. */
2402- static bool receiver_chain_admits (const char * callee_name , const char * candidate_qn ) {
2421+ * One exception, for C# CALLS only (#2121): C# spells its built-in types as
2422+ * lower-case keywords, so in `int.TryParse` or `string.Join` the root names a
2423+ * type and gets the same check (cs_type_keyword_root). `lang` is the calling
2424+ * file's language on the CALLS path (cbm_registry_resolve_call_lang) and
2425+ * CBM_LANG_COUNT on every other resolve. In Python, JS or Go these words are
2426+ * ordinary identifiers, so a variable named `object` stays a value root there.
2427+ *
2428+ * Otherwise language agnostic by design: every language that writes receiver
2429+ * chains gains the same protection. */
2430+ static bool receiver_chain_admits (const char * callee_name , const char * candidate_qn ,
2431+ CBMLanguage lang ) {
24032432 /* Normalize "::" -> "." so the chain composes with dotted candidate QNs,
24042433 * the same way qualified_suffix_match does. */
24052434 char dotted [CBM_SZ_512 ];
@@ -2418,7 +2447,8 @@ static bool receiver_chain_admits(const char *callee_name, const char *candidate
24182447 if (!last_dot ) {
24192448 return true; /* bare name — no receiver chain to judge */
24202449 }
2421- if (dotted [0 ] < 'A' || dotted [0 ] > 'Z' ) {
2450+ if ((dotted [0 ] < 'A' || dotted [0 ] > 'Z' ) &&
2451+ !(lang == CBM_LANG_CSHARP && cs_type_keyword_root (dotted ))) {
24222452 return true; /* lower-case root names a value, not a type */
24232453 }
24242454 /* A name written in capitals with underscores is a constant holding a
@@ -2506,10 +2536,12 @@ static void candidates_without_members(const cbm_registry_t *r, const qn_array_t
25062536 .lang = side ? lang : NULL };
25072537}
25082538
2509- /* Strategies 3.5, 3 and 4 over one same-name candidate set. */
2539+ /* Strategies 3.5, 3 and 4 over one same-name candidate set. `lang` reaches
2540+ * receiver_chain_admits only (see there). */
25102541static cbm_resolution_t resolve_name_candidates (const cbm_registry_t * r , const qn_array_t * arr ,
25112542 const char * callee_name , const char * module_qn ,
2512- const char * * import_vals , int import_count ) {
2543+ const char * * import_vals , int import_count ,
2544+ CBMLanguage lang ) {
25132545 /* Strategy 3.5: a qualified callee disambiguates among multiple same-name
25142546 * candidates by full qualified tail, before bare-name scoring collapses
25152547 * them onto a single winner. */
@@ -2522,7 +2554,7 @@ static cbm_resolution_t resolve_name_candidates(const cbm_registry_t *r, const q
25222554
25232555 /* Strategy 3: unique name */
25242556 if (arr -> count == SKIP_ONE ) {
2525- if (!receiver_chain_admits (callee_name , arr -> items [0 ])) {
2557+ if (!receiver_chain_admits (callee_name , arr -> items [0 ], lang )) {
25262558 return empty_result ();
25272559 }
25282560 double conf = CONF_UNIQUE_NAME ;
@@ -2540,7 +2572,7 @@ static cbm_resolution_t resolve_name_candidates(const cbm_registry_t *r, const q
25402572 const char * best = best_by_import_distance (r , (const char * * )arr -> items , qn_test_flags (arr ),
25412573 qn_lang_flags (arr ), arr -> count , module_qn );
25422574 if (best ) {
2543- if (!receiver_chain_admits (callee_name , best )) {
2575+ if (!receiver_chain_admits (callee_name , best , lang )) {
25442576 return empty_result ();
25452577 }
25462578 double conf = candidate_count_penalty (CONF_SUFFIX_MATCH , arr -> count );
@@ -2558,7 +2590,7 @@ static cbm_resolution_t resolve_name_candidates(const cbm_registry_t *r, const q
25582590 * libc `read()` the unique name of a C++ adapter's Method instead. */
25592591static cbm_resolution_t resolve_name_lookup (const cbm_registry_t * r , const char * callee_name ,
25602592 const char * module_qn , const char * * import_vals ,
2561- int import_count , bool skip_members ) {
2593+ int import_count , bool skip_members , CBMLanguage lang ) {
25622594 const char * lookup = simple_name (callee_name );
25632595 const qn_array_t * arr = cbm_ht_get (r -> by_name , lookup );
25642596 if (!arr || arr -> count == 0 ) {
@@ -2576,17 +2608,20 @@ static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const char
25762608 if (view .count == 0 ) {
25772609 return empty_result ();
25782610 }
2579- return resolve_name_candidates (r , & view , callee_name , module_qn , import_vals , import_count );
2611+ return resolve_name_candidates (r , & view , callee_name , module_qn , import_vals , import_count ,
2612+ lang );
25802613 }
2581- return resolve_name_candidates (r , arr , callee_name , module_qn , import_vals , import_count );
2614+ return resolve_name_candidates (r , arr , callee_name , module_qn , import_vals , import_count , lang );
25822615}
25832616
25842617/* The strategy chain shared by both public resolve variants (no caching here —
2585- * cbm_registry_resolve owns the per-file cache). */
2618+ * cbm_registry_resolve owns the per-file cache). `lang`: see
2619+ * receiver_chain_admits. */
25862620static cbm_resolution_t registry_resolve_chain (const cbm_registry_t * r , const char * callee_name ,
25872621 const char * module_qn , const char * * import_map_keys ,
25882622 const char * * import_map_vals , int import_map_count ,
2589- size_t scope_len , bool skip_members ) {
2623+ size_t scope_len , bool skip_members ,
2624+ CBMLanguage lang ) {
25902625 /* Split callee at the first path separator: "pkg.Func" → prefix="pkg",
25912626 * suffix="Func". Rust/C++ use "::" rather than ".", so honor whichever
25922627 * separator appears first ("lib::square" → prefix="lib", suffix="square").
@@ -2624,7 +2659,7 @@ static cbm_resolution_t registry_resolve_chain(const cbm_registry_t *r, const ch
26242659 if (!(res .qualified_name && res .qualified_name [0 ])) {
26252660 /* Strategy 3+4: name lookup */
26262661 res = resolve_name_lookup (r , callee_name , module_qn , import_map_vals , import_map_count ,
2627- skip_members );
2662+ skip_members , lang );
26282663 }
26292664 return res ;
26302665}
@@ -2672,25 +2707,31 @@ bool cbm_registry_name_guess_vetoed(const cbm_registry_t *r, CBMLanguage caller_
26722707 registry_entry_language (r , res -> qualified_name ));
26732708}
26742709
2710+ /* call_lang: the calling file's language for a CALLS resolve, CBM_LANG_COUNT
2711+ * for every other one (see receiver_chain_admits). */
26752712static cbm_resolution_t registry_resolve_scoped (const cbm_registry_t * r , const char * callee_name ,
26762713 const char * module_qn , const char * * import_map_keys ,
26772714 const char * * import_map_vals , int import_map_count ,
2678- size_t scope_len , bool skip_members ) {
2715+ size_t scope_len , bool skip_members ,
2716+ CBMLanguage call_lang ) {
26792717 if (!r || !callee_name ) {
26802718 return empty_result ();
26812719 }
26822720
26832721 /* Per-file cache: same callee_name in N call sites → 1 chain walk
26842722 * + N-1 O(1) hash hits. module_qn is constant per file so the
2685- * cache key only needs callee_name. */
2723+ * cache key only needs callee_name. The chain reads call_lang only as
2724+ * "is it C#", so that one bit is all the entry has to record. */
2725+ bool cs_keywords = call_lang == CBM_LANG_CSHARP ;
26862726 resolve_cache_entry_t * cached =
26872727 _resolve_cache ? (resolve_cache_entry_t * )cbm_ht_get (_resolve_cache , callee_name ) : NULL ;
2688- if (cached && cached -> scope_len == scope_len && cached -> skip_members == skip_members )
2728+ if (cached && cached -> scope_len == scope_len && cached -> skip_members == skip_members &&
2729+ cached -> cs_keywords == cs_keywords )
26892730 return cached -> res ;
26902731
26912732 cbm_resolution_t res =
26922733 registry_resolve_chain (r , callee_name , module_qn , import_map_keys , import_map_vals ,
2693- import_map_count , scope_len , skip_members );
2734+ import_map_count , scope_len , skip_members , call_lang );
26942735
26952736 /* Data relations (Table/View) are lineage-only registry members: common
26962737 * table names (users, orders, config) collide with code identifiers across
@@ -2711,12 +2752,14 @@ static cbm_resolution_t registry_resolve_scoped(const cbm_registry_t *r, const c
27112752 cached -> res = res ;
27122753 cached -> scope_len = scope_len ;
27132754 cached -> skip_members = skip_members ;
2755+ cached -> cs_keywords = cs_keywords ;
27142756 } else if (_resolve_cache ) {
27152757 resolve_cache_entry_t * e = (resolve_cache_entry_t * )malloc (sizeof (* e ));
27162758 if (e ) {
27172759 e -> res = res ;
27182760 e -> scope_len = scope_len ;
27192761 e -> skip_members = skip_members ;
2762+ e -> cs_keywords = cs_keywords ;
27202763 char * kdup = strdup (callee_name );
27212764 if (kdup ) {
27222765 cbm_ht_set (_resolve_cache , kdup , e );
@@ -3734,7 +3777,7 @@ int cbm_registry_swift_candidates(const cbm_registry_t *r, const CBMCall *call,
37343777 const char * qn = bucket -> items [i ];
37353778 swift_signature_t * meta = cbm_ht_get (r -> swift_signatures , qn );
37363779 has_swift = has_swift || meta != NULL ;
3737- if (meta && receiver_chain_admits (call -> callee_name , qn ) &&
3780+ if (meta && receiver_chain_admits (call -> callee_name , qn , CBM_LANG_SWIFT ) &&
37383781 swift_signature_matches (meta , call )) {
37393782 matches [matched ++ ] = qn ;
37403783 }
@@ -4445,7 +4488,8 @@ cbm_resolution_t cbm_registry_resolve(const cbm_registry_t *r, const char *calle
44454488 const char * module_qn , const char * * import_map_keys ,
44464489 const char * * import_map_vals , int import_map_count ) {
44474490 return registry_resolve_scoped (r , callee_name , module_qn , import_map_keys , import_map_vals ,
4448- import_map_count , module_qn ? strlen (module_qn ) : 0 , false);
4491+ import_map_count , module_qn ? strlen (module_qn ) : 0 , false,
4492+ CBM_LANG_COUNT );
44494493}
44504494
44514495static size_t lang_scope_len (const char * module_qn , CBMLanguage lang ) {
@@ -4458,7 +4502,8 @@ cbm_resolution_t cbm_registry_resolve_lang(const cbm_registry_t *r, const char *
44584502 const char * * import_map_vals , int import_map_count ,
44594503 CBMLanguage lang ) {
44604504 return registry_resolve_scoped (r , callee_name , module_qn , import_map_keys , import_map_vals ,
4461- import_map_count , lang_scope_len (module_qn , lang ), false);
4505+ import_map_count , lang_scope_len (module_qn , lang ), false,
4506+ CBM_LANG_COUNT );
44624507}
44634508
44644509cbm_resolution_t cbm_registry_resolve_call_lang (const cbm_registry_t * r , const char * callee_name ,
@@ -4472,7 +4517,8 @@ cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const c
44724517 bool skip_members = lang == CBM_LANG_C && callee_name && !strchr (callee_name , '.' ) &&
44734518 !strstr (callee_name , "->" );
44744519 return registry_resolve_scoped (r , callee_name , module_qn , import_map_keys , import_map_vals ,
4475- import_map_count , lang_scope_len (module_qn , lang ), skip_members );
4520+ import_map_count , lang_scope_len (module_qn , lang ), skip_members ,
4521+ lang );
44764522}
44774523
44784524/* ── Class-qualified route handlers (PHP, #1146) ─────────────────── */
@@ -4640,7 +4686,8 @@ cbm_resolution_t cbm_registry_resolve_lineage(const cbm_registry_t *r, const cha
46404686 * it would poison one variant with the other's semantics. SQL files hold
46414687 * few distinct relation refs, so the chain walk stays cheap. */
46424688 return registry_resolve_chain (r , callee_name , module_qn , import_map_keys , import_map_vals ,
4643- import_map_count , module_qn ? strlen (module_qn ) : 0 , false);
4689+ import_map_count , module_qn ? strlen (module_qn ) : 0 , false,
4690+ CBM_LANG_COUNT );
46444691}
46454692
46464693/* Python looks a bare name up in the calling def's own scope, then in each
0 commit comments