Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't check constraints on methods which are not substituted #74487

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (method.Arity == 0 || method.TypeSubstitution is null)
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method.Arity == 0 || method.TypeSubstitution is null

!RequiresChecking(method)? #Closed

{
return true;
}
Expand Down
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 Foo<T>;
Copy link
Contributor

@AlekseyTs AlekseyTs Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foo

This word is getting flagged by Policheck tool #Closed

static class FooExt
{
public static void Bar<T>(this Foo<T> foo)
{
foo.Bar = 42;
}
}
""";
var comp = CreateCompilation(source);
comp.VerifyEmitDiagnostics(
// (7,9): error CS1656: Cannot assign to 'Bar' because it is a 'method group'
// foo.Bar = 42;
Diagnostic(ErrorCode.ERR_AssgReadonlyLocalCause, "foo.Bar").WithArguments("Bar", "method group").WithLocation(7, 9));
}
}
}