Extension method with constraint we're unable to check is silently skipped over
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
In the following test, I would expect that an error be reported for `E.M` since there is a use-site problem with checking the constraint.
`OverloadResolution.FailsConstraintChecks` is a good place to start.
```csharp
[Fact]
public void TODO2()
{
var missingSrc = """
public struct Missing { public int i; }
""";
var missingRef = CreateCompilation(missingSrc, assemblyName: "missing").EmitToImageReference();
var containerSrc = """
public struct Container { public Missing field; }
""";
var containerRef = CreateCompilation(containerSrc, references: [missingRef]).EmitToImageReference();
var src = """
using N;
new Container().M();
static class E
{
public static void M(this T t) where T : unmanaged { }
}
namespace N
{
static class E2
{
public static void M(this T t) { }
}
}
""";
var comp = CreateCompilation(src, references: [containerRef]);
comp.VerifyEmitDiagnostics();
}
```
Contributor guide
Research direction
Start with OverloadResolution.FailsConstraintChecks, then add the supplied TODO2 test near the existing constraint-check coverage. Run the test and inspect its diagnostics; done means the use-site constraint problem produces an error for E.M instead of the extension method being silently skipped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100