Skip to content

Commit

Permalink
Don't check constraints on methods which are not substituted (#74487)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson committed Jul 23, 2024
1 parent 6eb1686 commit 4885729
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10562,7 +10562,7 @@ static bool isCandidateUnique(ref MethodSymbol? foundMethod, MethodSymbol candid

bool satisfiesConstraintChecks(MethodSymbol method)
{
if (method.Arity == 0)
if (!ConstraintsHelper.RequiresChecking(method))
{
return true;
}
Expand Down
21 changes: 21 additions & 0 deletions src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4139,5 +4139,26 @@ public static void M(this A s, ref int i) {}
// public A(int x, A a = new A().M(1)) { }
Diagnostic(ErrorCode.ERR_BadArgRef, "1").WithArguments("2", "ref").WithLocation(8, 37));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/74404")]
public void Repro_74404()
{
var source = """
#nullable enable
class C<T>;
static class CExt
{
public static void M<T>(this C<T> c)
{
c.M = 42;
}
}
""";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics(
// (7,9): error CS1656: Cannot assign to 'M' because it is a 'method group'
// c.M = 42;
Diagnostic(ErrorCode.ERR_AssgReadonlyLocalCause, "c.M").WithArguments("M", "method group").WithLocation(7, 9));
}
}
}

0 comments on commit 4885729

Please sign in to comment.