-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
CS8619 for anonymous types with nullable ref types after VS update #51886
Comments
I can't reproduce in the current |
@Youssef1313 I did some more testing with a blank project and could not reproduce it either at first but I now think I've managed to pinpoint the root cause of this issue. It seems like the problem happens with EF Core (v. 5.0.4) in async functions where you try to save your changes in a loop with
I'm not sure if this has already been fixed in the efcore repo or if I should make a new issue about it there? It seems related to this issue: dotnet/efcore#19007 |
This does repro for me, producing the odd exception, but although EF is being used to trigger the error it doesn't seem to be involved in any way. Indeed looks like a compiler issue to me... |
I tried making some minimal modifications to make the sample build in SharpLab. However, it doesn't seem to produce a diagnostic. If you are able to produce a SharpLab which does produce the undesired diagnostic, that would be really helpful. |
@RikkiGibson If you add |
Came across this today after upgrading Visual Studio to 16.9.2 Using .NET Core 3.1 I can reproduce the issue with the following:
It seems the issue comes about when a property of an object is a nullable reference type, but is subsequently able to be inferred to be non-nullable (via an explicit check for null or via nullability attributes of calling method). The inferred type of the field in anonymous object is then determined to be non-nullable, which causes the mismatch. |
I'll need to look at this more closely to be sure I understand the issue, and particularly determine what we changed that made this start to become a problem, but at a glance I am wondering if this is another scenario where "nullable-covariant" conversions should be allowed. That is, if we simply allowed the anonymous type |
@RikkiGibson My understanding is that the anonymous types that differ only by property nullability are not created as separate types, but rather the exact same type generated by compiler. The following tests pass:
|
I noticed that the presence of the warning depends on whether 'default' is passed for the CancellationToken parameter. If you pass a non-'default' CancellationToken, there is no warning. Passing @cston I wondered if this is potentially related to the recent nullable lambda state optimizations. Is there a remote chance that the state of the |
@RikkiGibson Here is a SharpLab repro that doesn't involve default parameters |
Version Used:
.NET SDK: 5.0.201
Visual Studio: 16.9.1
Compiler: '3.9.0-6.21124.20 (db94f4c)'. Language version: 9.0
Steps to Reproduce:
After updating Visual Studio to version 16.9.1 (from 16.8.5 I think) I've started getting false positives when creating anonymous types with nullable reference types.
Creating an anonymous type like this with Select or GroupBy etc causes a CS8619 warning but I have a ruleset referenced in my csproj file that treats CS8619 with error severity so my project doesn't compile at all any longer.
Expected Behavior:
It should be possible to create anonymous types from types that has nullable reference types without getting a CS8619 warning.
Actual Behavior:
The compiler/analyzer wrongly wants the anonymous type to match an anonymous type with non nullable reference types:
CS8619 Nullability of reference types in value of type '<anonymous type: string NullableString>' doesn't match target type '<anonymous type: string? NullableString>'.
The text was updated successfully, but these errors were encountered: