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

Improve error message for explicit implementation of interface method #1760

Conversation

thomaslevesque
Copy link
Member

Fixes #1759

@thomaslevesque thomaslevesque force-pushed the better-explicit-implementation-error-message branch from 870e0b9 to aa31430 Compare April 8, 2020 22:20
@thomaslevesque thomaslevesque marked this pull request as ready for review April 8, 2020 22:33
@thomaslevesque
Copy link
Member Author

I have hundreds of warnings in the T4-generated files... They were gone in previous builds, and now they're back. I also have them locally.
The only thing that changed, as far as I can tell, is the .NET Core SDK.

@thomaslevesque
Copy link
Member Author

Confirmed: if I force the use of the 3.0 SDK instead of 3.1, I don't have any warnings.
You had reported the problem in VS Dev Community, but it looks like they won't do anything about it... Did you also report it on Github? I can't remember

@thomaslevesque
Copy link
Member Author

thomaslevesque commented Apr 8, 2020

Oh, actually it's not the same warning!
Before, we had this:

warning CS8632: The annotation for nullable reference types should only be used in code within a ‘#nullable’ annotations context

Now we have this:

warning CS8604: Possible null reference argument for parameter 'arg' in 'object?[] Func<T1, object?[]>.Invoke(T1 arg)'.

(if I remove the #nullable enable, I get the old warning again)

@thomaslevesque
Copy link
Member Author

The new warning seems legit. We have this:

return valueProducer(call.GetArgument<T1>(0)!);

valueProducer is a Func<T1, object?[]>, and GetArgument has a [return: MaybeNull] attribute. So we could be passing a null T1 argument for a non-null T1 parameter. But I don't know how to say "T1 in Func<T1, object?[]> can be null". I can't use T1?, because there's no constraint on T1.
I can just add ! after the call to GetArgument, but it's frustrating...

@thomaslevesque
Copy link
Member Author

OK, so according to dotnet/roslyn#37829, it's by design that <Nullable>enabled</Nullable> is ignored in generated code.
What has changed is that the compiler now reports more nullability warnings.

@blairconrad blairconrad merged commit 57897e1 into FakeItEasy:master Apr 9, 2020
@blairconrad
Copy link
Member

Perfect, @thomaslevesque. Thanks!

@thomaslevesque thomaslevesque deleted the better-explicit-implementation-error-message branch April 9, 2020 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message when configuring explicitly implemented interface method
2 participants