-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Report AdditionalLocations for CS8618 (uninitialized non-nullable member) #58096
Report AdditionalLocations for CS8618 (uninitialized non-nullable member) #58096
Conversation
|
||
var property = comp.GetTypeByMetadataName("C").GetMember("S"); | ||
var actualAdditionalLocations = comp.GetDiagnostics().Single().AdditionalLocations; | ||
Assert.Equal(property.Locations.Single(), actualAdditionalLocations.Single()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Youssef1313 not sure the additional location makes sense when the diagnostic is issued on the property (i.e. no constructor), but I'm not sure what the conventions are here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll let someone from the compiler team weigh on how this should behave. My intention was to allow the use of AdditionalLocations
in all cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think not having to think about whether to use AdditionalLocations or not is the correct move.
Closing and re-opening for a new build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (commit 1). @dotnet/roslyn-compiler for a second review.
@jcouv @RikkiGibson Can I get a second review here? Thanks! |
comp.VerifyDiagnostics( | ||
// (4,12): warning CS8618: Non-nullable property 'S' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. | ||
// public C() { } | ||
Diagnostic(ErrorCode.WRN_UninitializedNonNullableField, "C").WithArguments("property", "S").WithLocation(4, 12)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's slightly unfortunate that this generated baseline doesn't include the additional locations.
Thanks for the contribution @Youssef1313! |
@RikkiGibson and others, I'm testing with dotnet SDK 7.0.100-preview.3.22179.4 and the AdditionalLocations property on the diagnostic is empty - can you confirm this came out with preview3? (it's always a bit difficult to understand which SDK version the VS version maps to) |
This change should definitely be in preview3. What's the scenario/environment where you observe that AdditionalLocations is empty? |
Apologies, I can no longer reproduce the issue and am seeing the populated AdditionalLocations (possibly a caching issue after upgrading or something). Thanks for the quick response. |
@RikkiGibson sorry, one last question... If I'm understanding everything correctly, I can see AdditionalLocations populated when referencing Microsoft.CodeAnalysis.CSharp 4.2.0-2.final, but not when referencing 4.1.0. Is 4.2.0-2.final the equivalent of the Roslyn that's included in SDK 7.0.0-preview.3, and will 4.2.0 be released at the same time as .NET 7.0? |
It looks like preview3 has some build of 4.2.0-4. The way I answer these questions is by querying PRs to dotnet/sdk.
4.2.0 will be released sooner than .NET 7.0, I think. See the (internal) dev17.2 schedule and NET 7 schedule. |
Thanks again @RikkiGibson. |
Fixes #58073