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

.NET 6 RC 1: changes to overload resolution? Breaks NUnit? #56167

Closed
jonathanpeppers opened this issue Sep 3, 2021 · 2 comments · Fixed by #56341
Closed

.NET 6 RC 1: changes to overload resolution? Breaks NUnit? #56167

jonathanpeppers opened this issue Sep 3, 2021 · 2 comments · Fixed by #56341

Comments

@jonathanpeppers
Copy link
Member

Version Used:

> dotnet --version
6.0.100-rc.1.21452.4

Steps to Reproduce:

  1. Unzip this somewhere: repro.zip
  2. dotnet build fails with:
Program.cs(3,8): error CS0121: The call is ambiguous between the following methods or properties: 'Assert.That(TestDelegate, IResolveConstraint)' and 'Assert.That<TActual>(TActual, IResolveConstraint)'
  1. If you uncomment <LangVersion>9.0</LangVersion> it works.

The problematic method is NUnit:

Assert.That(() => { }, Throws.Nothing);

We hit this in .NET MAUI here:

dotnet/maui#2369

The breaking change might be expected. The part that is concerning, is we had some unit tests fail at runtime due to a similar issue, where changing LangVersion=9.0 fixed the test failure:

https://github.com/dotnet/maui/blob/f22a61ac027bb115a115a0f493c97ba0c98fa3e8/src/Core/tests/UnitTests/LifecycleEvents/LifecycleEventsTests.cs#L119-L136

I thought it might be worth checking into, thanks!

Expected Behavior:

NUnit Assert.That(() => { }, Throws.Nothing); compiles in C# 10?

Actual Behavior:

NUnit Assert.That(() => { }, Throws.Nothing); doesn't compile under C# 10.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Sep 3, 2021
@cston cston self-assigned this Sep 3, 2021
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Sep 3, 2021
@jcouv jcouv added this to the 17.0 milestone Sep 3, 2021
@cston
Copy link
Member

cston commented Sep 3, 2021

Thanks @jonathanpeppers for reporting these cases.

The part that is concerning, is we had some unit tests fail at runtime due to a similar issue, where changing LangVersion=9.0 fixed the test failure:

https://github.com/dotnet/maui/blob/f22a61ac027bb115a115a0f493c97ba0c98fa3e8/src/Core/tests/UnitTests/LifecycleEvents/LifecycleEventsTests.cs#L119-L136

It looks like the lambda expressions in the test may be binding to the generic overload with TDelegate = Func<int> rather than the overload with Action.

@jonathanpeppers
Copy link
Member Author

Repro steps for the second issue, this failing test.

  1. Clone dotnet/maui
  2. Checkout the release/6.0.1xx-rc1 branch
  3. dotnet build src/DotNet/DotNet.csproj - will create a .NET SDK in ./bin/dotnet/ and install optional workloads
  4. ./bin/dotnet/dotnet test src/Core/tests/UnitTests/Core.UnitTests-net6.csproj -p:LangVersion=10.0

This actually shows 3 test failures, but they all appear to be the same thing. You can drop -p:LangVersion and the problem goes away, because we currently have LangVersion=9.0 in the .csproj file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment