C#: extension fallback binds an instance call to an incompatible extension method #397

Closed
opened 2026-10-20 11:27:05 +02:00 by buildagent · 1 comment
Member

Confirmed on the signed, shipped runtime v0.41.1 (419f349b) with the published C# 0.1.5 package (sha256:cc393ce325dabec0ad21b68716194e84e48e2cfc88dfed68f3b8aad12f79885c). Project ownership was checked as package / de.h-dv.csharp; the tested CIP is byte-identical to the published CIP.

Minimal fixture, with each declaration in its own file:

// TextExtensions.cs
namespace App;
public static class TextExtensions {
    public static string Describe(this string value) { return value; }
}
// Widget.cs
namespace App;
public sealed class Widget {
    public string Describe() { return "widget"; }
}
// UseWidget.cs
namespace App;
public static class UseWidget {
    public static string Run() {
        var widget = new Widget();
        return widget.Describe();
    }
}

Compiler oracle: .NET SDK 9.0.118, offline restore with no package sources, compiled the three files plus System.Console.WriteLine(App.UseWidget.Run()); and printed widget. The instance method is the target; the extension's this string parameter is incompatible with Widget.

Observed index result: after indexing with the package enabled and csharp = "package", search_symbols finds UseWidget.Run. find_callees returns the Describe call as resolution: resolved, resolved_by: csharp_extension, qualifier: widget, targeting App.TextExtensions.Describe. It reports one resolved call and zero unresolved calls. The correct App.Widget.Describe declaration is present in the same index.

The reproduction lives in /tmp/cosi-csharp-call-baseline/ (extension-callees.json, extension-ownership.json) and the compiler oracle in /tmp/cosi-csharp-extension-oracle/ (run.log, index-targets.json) on the build machine. The inline fixture is sufficient to recreate it elsewhere.

The Tier EXT pass in crates/indexer/src/index.rs admits a unique reachable extension candidate without proving receiver compatibility. When the ordinary receiver-origin pass cannot resolve this instance call, that fallback creates a wrong edge.

Acceptance:

  • Add this compiler-backed precision regression; require the exact Widget target, or an explicitly unresolved call until it can be proven.
  • Require receiver compatibility and instance-member precedence before admitting an extension target. An unsupported receiver must remain unresolved.
  • Keep a valid string receiver positive control for the extension and namespace/project/overload decoys, including deletion/restoration.
  • Measure any change against the C# corpus and existing performance budgets.

Related: #313 requests extension recall for unknown receivers and explicitly requires no wrong binds. This is a precision blocker for advertising the C# plugin as fully production ready.

Confirmed on the signed, shipped runtime **v0.41.1 (`419f349b`)** with the published **C# 0.1.5** package (`sha256:cc393ce325dabec0ad21b68716194e84e48e2cfc88dfed68f3b8aad12f79885c`). Project ownership was checked as `package` / `de.h-dv.csharp`; the tested CIP is byte-identical to the published CIP. Minimal fixture, with each declaration in its own file: ```csharp // TextExtensions.cs namespace App; public static class TextExtensions { public static string Describe(this string value) { return value; } } ``` ```csharp // Widget.cs namespace App; public sealed class Widget { public string Describe() { return "widget"; } } ``` ```csharp // UseWidget.cs namespace App; public static class UseWidget { public static string Run() { var widget = new Widget(); return widget.Describe(); } } ``` **Compiler oracle:** .NET SDK 9.0.118, offline restore with no package sources, compiled the three files plus `System.Console.WriteLine(App.UseWidget.Run());` and printed `widget`. The instance method is the target; the extension's `this string` parameter is incompatible with `Widget`. **Observed index result:** after indexing with the package enabled and `csharp = "package"`, `search_symbols` finds `UseWidget.Run`. `find_callees` returns the `Describe` call as `resolution: resolved`, `resolved_by: csharp_extension`, `qualifier: widget`, targeting **App.TextExtensions.Describe**. It reports one resolved call and zero unresolved calls. The correct **App.Widget.Describe** declaration is present in the same index. The reproduction lives in `/tmp/cosi-csharp-call-baseline/` (`extension-callees.json`, `extension-ownership.json`) and the compiler oracle in `/tmp/cosi-csharp-extension-oracle/` (`run.log`, `index-targets.json`) on the build machine. The inline fixture is sufficient to recreate it elsewhere. The `Tier EXT` pass in `crates/indexer/src/index.rs` admits a unique reachable extension candidate without proving receiver compatibility. When the ordinary receiver-origin pass cannot resolve this instance call, that fallback creates a wrong edge. Acceptance: - Add this compiler-backed precision regression; require the exact Widget target, or an explicitly unresolved call until it can be proven. - Require receiver compatibility and instance-member precedence before admitting an extension target. An unsupported receiver must remain unresolved. - Keep a valid `string` receiver positive control for the extension and namespace/project/overload decoys, including deletion/restoration. - Measure any change against the C# corpus and existing performance budgets. Related: #313 requests extension recall for unknown receivers and explicitly requires no wrong binds. This is a precision blocker for advertising the C# plugin as fully production ready.
Author
Member

A capability control was also run on the same fixture with the shipped v0.41.1 runtime and published C# 0.1.5:

  1. Enable the package with its requested resolver capabilities except extension_methods, then run code-index index.
  2. find_callees(..., include_unresolved=true) retains the extracted Describe call with target_id: null / resolution: unresolved. Ownership remains package, and extraction_grant_refusals.files is 0.
  3. Restore --grant requested, reindex, and the wrong csharp_extension bind returns.
  4. Withhold extension_methods again and reindex: the wrong edge clears again.

The tested subset was same_file_candidate,exported_candidate,reachability_anchor,qualified_candidate,type_position_candidate,member_candidate. This is a mitigation for the false extension edge; it does not resolve the correct instance target. Logs are extension-grant-*, extension-callees-* and extension-ownership-* in the reproduction directory. Watcher transport was not tested by this control.

A capability control was also run on the same fixture with the shipped v0.41.1 runtime and published C# 0.1.5: 1. Enable the package with its requested resolver capabilities **except `extension_methods`**, then run `code-index index`. 2. `find_callees(..., include_unresolved=true)` retains the extracted `Describe` call with `target_id: null` / `resolution: unresolved`. Ownership remains `package`, and `extraction_grant_refusals.files` is 0. 3. Restore `--grant requested`, reindex, and the wrong `csharp_extension` bind returns. 4. Withhold `extension_methods` again and reindex: the wrong edge clears again. The tested subset was `same_file_candidate,exported_candidate,reachability_anchor,qualified_candidate,type_position_candidate,member_candidate`. This is a mitigation for the false extension edge; it does not resolve the correct instance target. Logs are `extension-grant-*`, `extension-callees-*` and `extension-ownership-*` in the reproduction directory. Watcher transport was not tested by this control.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
h-dv/code-index#397
No description provided.