From 0b0fefcbff2a63bd969d9695d51417a18c1d39d1 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Tue, 21 Apr 2026 18:59:13 +0100 Subject: [PATCH] =?UTF-8?q?feat(csharp-scope):=20parity=20Unit=202c=20?= =?UTF-8?q?=E2=80=94=20alias/await/return-type=20captures?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes 7 parity failures (34 → 27). Adds the remaining type-binding shapes the parity suite exercises: - `var alias = u;` / `alias = u;` — identifier-to-identifier alias. The resolver's chain-follow walks alias → u → u's declared type. - `var u = svc.GetUser();` — chained method call alias. Anchors on the method_access_expression's `name` field; chain-follow picks up GetUser's return type. - `var u = await Factory();` / `await svc.Get();` — await propagation. Strips the `await_expression` wrapper; interpret layer's `stripGeneric` handles `Task` / `ValueTask` unwrapping. - `public User GetUser() { ... }` — method return-type annotation via `@type-binding.return`. Required for `propagateImportedReturnTypes` to see the return type in later cross-file passes. Covers identifier, generic_name, qualified_name, and nullable_type return shapes. 74/74 scope-resolution unit tests pass; legacy path 175/175 green; 27 parity failures remain under REGISTRY_PRIMARY_CSHARP=1. --- .../core/ingestion/languages/csharp/query.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/gitnexus/src/core/ingestion/languages/csharp/query.ts b/gitnexus/src/core/ingestion/languages/csharp/query.ts index 6dbe5e6b2..9224339cf 100644 --- a/gitnexus/src/core/ingestion/languages/csharp/query.ts +++ b/gitnexus/src/core/ingestion/languages/csharp/query.ts @@ -195,6 +195,77 @@ const CSHARP_SCOPE_QUERY = ` (invocation_expression function: (identifier) @type-binding.type)))) @type-binding.alias +;; Type bindings — identifier-to-identifier alias: \`var alias = u;\`. +;; The resolver's chain-follow walks from \`alias\` → \`u\` → u's +;; declared type, so we only need to tag the rename here. +(local_declaration_statement + (variable_declaration + type: (implicit_type) + (variable_declarator + name: (identifier) @type-binding.name + (identifier) @type-binding.type))) @type-binding.alias + +;; Type bindings — chained method-call alias: \`var u = svc.GetUser();\`. +;; The chain-follow then walks GetUser's return-type binding. +(local_declaration_statement + (variable_declaration + type: (implicit_type) + (variable_declarator + name: (identifier) @type-binding.name + (invocation_expression + function: (member_access_expression + name: (identifier) @type-binding.type))))) @type-binding.alias + +;; Type bindings — \`await\` propagation: \`var u = await Factory();\`. +;; Strip the await wrapper to get the underlying invocation; interpret +;; layer's stripGeneric handles Task / ValueTask. +(local_declaration_statement + (variable_declaration + type: (implicit_type) + (variable_declarator + name: (identifier) @type-binding.name + (await_expression + (invocation_expression + function: (identifier) @type-binding.type))))) @type-binding.alias + +(local_declaration_statement + (variable_declaration + type: (implicit_type) + (variable_declarator + name: (identifier) @type-binding.name + (await_expression + (invocation_expression + function: (member_access_expression + name: (identifier) @type-binding.type)))))) @type-binding.alias + +;; Type bindings — identifier-to-identifier assignment rebind: +;; \`alias = u;\` — aliases the rhs identifier's current type. +(assignment_expression + left: (identifier) @type-binding.name + right: (identifier) @type-binding.type) @type-binding.alias + +;; Type bindings — method return type: \`public User GetUser() { ... }\`. +;; Anchor on the method_declaration so bindingScopeFor can hoist the +;; binding from function scope to the enclosing class/module scope +;; (callers, not the function body, look up the return type by the +;; function's name). Required for cross-file return-type propagation +;; via propagateImportedReturnTypes. +(method_declaration + returns: (identifier) @type-binding.type + name: (identifier) @type-binding.name) @type-binding.return + +(method_declaration + returns: (generic_name) @type-binding.type + name: (identifier) @type-binding.name) @type-binding.return + +(method_declaration + returns: (qualified_name) @type-binding.type + name: (identifier) @type-binding.name) @type-binding.return + +(method_declaration + returns: (nullable_type) @type-binding.type + name: (identifier) @type-binding.name) @type-binding.return + ;; Type bindings — field declaration: \`private City _city;\`. Attaches ;; to the enclosing class scope via positionIndex, so \`this._city.X\` ;; can look up _city's type on the class.