Skip to content

Commit

Permalink
Adjust asserts in OverloadResolutionResult.ReportDiagnostics. (#55899)
Browse files Browse the repository at this point in the history
Fixes #52701.
  • Loading branch information
AlekseyTs committed Aug 26, 2021
1 parent 7e51135 commit 52b1b57
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,6 @@ internal void ReportDiagnostics<T>(
// there also can't be a single one. Therefore, there are none.
AssertNone(MemberResolutionKind.Worse);

// If there's a less-derived candidate, it must be less derived than some applicable or
// "worse" candidate. Since there are none of those, there must not be any less-derived
// candidates either.
AssertNone(MemberResolutionKind.LessDerived);


//// PHASE 2: Applicability failures ////

// Overload resolution performed these checks just before weeding out less-derived and worse candidates.
Expand Down Expand Up @@ -305,6 +299,11 @@ internal void ReportDiagnostics<T>(
// Since we didn't return...
AssertNone(MemberResolutionKind.ConstraintFailure);

// If there's a less-derived candidate, it must be less derived than some applicable or
// "worse" candidate. Since there are none of those, there must not be any less-derived
// candidates either.
AssertNone(MemberResolutionKind.LessDerived);

// Otherwise, if there is any such method that has a bad argument conversion or out/ref mismatch
// then the first such method found is the best bad method.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11411,5 +11411,61 @@ static void verify(CSharpCompilation comp, SyntaxTree tree)
Assert.Equal("event D<A, B> Base<A, B>.E", symbol.ToTestDisplayString());
}
}

[Fact]
[WorkItem(52701, "https://github.com/dotnet/roslyn/issues/52701")]
public void Issue52701_01()
{
var source =
@"
class A
{
internal void F<T>(T t) where T : class {}
}
class B : A
{
internal new void F<T>(T t) where T : struct { }
void M()
{
System.Action<object> d = F<object>;
}
}
";

var comp = CreateCompilation(source);
comp.VerifyDiagnostics(
// (11,35): error CS0453: The type 'object' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'B.F<T>(T)'
// System.Action<object> d = F<object>;
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "F<object>").WithArguments("B.F<T>(T)", "T", "object").WithLocation(11, 35)
);
}

[Fact]
[WorkItem(52701, "https://github.com/dotnet/roslyn/issues/52701")]
public void Issue52701_02()
{
var source =
@"
class A
{
internal void F<T>(T t) where T : class {}
}
class B : A
{
internal new void F<T>(T t) where T : struct { }
void M()
{
F<object>(default);
}
}
";

var comp = CreateCompilation(source);
comp.VerifyDiagnostics(
// (11,9): error CS0453: The type 'object' must be a non-nullable value type in order to use it as parameter 'T' in the generic type or method 'B.F<T>(T)'
// F<object>(default);
Diagnostic(ErrorCode.ERR_ValConstraintNotSatisfied, "F<object>").WithArguments("B.F<T>(T)", "T", "object").WithLocation(11, 9)
);
}
}
}

0 comments on commit 52b1b57

Please sign in to comment.