Fix issue with 'remove unnecessary suppression' and field/property initializers#81899
Merged
CyrusNajmabadi merged 10 commits intoJan 15, 2026
Merged
Conversation
Contributor
Author
|
@dotnet/roslyn-ide ptal. |
Youssef1313
reviewed
Jan 7, 2026
|
|
||
| class C | ||
| { | ||
| public C() { } |
Member
There was a problem hiding this comment.
Consider testing when C is a partial class split into two files, with constructor in one file and the property in the other.
Contributor
Author
|
@JoeRobich ptal. We're going to go with this for now, over a compiler fix since the compiler can't commit to fixing immediately. |
JoeRobich
approved these changes
Jan 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #81843
The core issue here is a problem with the compiler's
GetDiagnostics(TextSpan). This works mostly as expected, except when it comes to nullable warnings. It's possible to ask for the diagnostics for a field/property and not get nullable warnings that would be computed if you asked for all diagnostics.This is because the compiler ends up not computing the field/prop nullable diagnostics if the span of type's constructor is not in what is requested.
This is a possible fix if teh compiler side is not fixed. In this case, we solve it by asking for diagnostics for the entire type, and then filtering to the spans that intersect the field/prop in question.