Skip to content

Fix issue with 'remove unnecessary suppression' and field/property initializers#81899

Merged
CyrusNajmabadi merged 10 commits into
dotnet:mainfrom
CyrusNajmabadi:removeSuppressionBugFix
Jan 15, 2026
Merged

Fix issue with 'remove unnecessary suppression' and field/property initializers#81899
CyrusNajmabadi merged 10 commits into
dotnet:mainfrom
CyrusNajmabadi:removeSuppressionBugFix

Conversation

@CyrusNajmabadi

Copy link
Copy Markdown
Contributor

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.

@CyrusNajmabadi

Copy link
Copy Markdown
Contributor Author

@dotnet/roslyn-ide ptal.


class C
{
public C() { }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider testing when C is a partial class split into two files, with constructor in one file and the property in the other.

@CyrusNajmabadi

Copy link
Copy Markdown
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.

@CyrusNajmabadi CyrusNajmabadi merged commit 5e97c82 into dotnet:main Jan 15, 2026
26 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the removeSuppressionBugFix branch January 15, 2026 21:27
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Jan 15, 2026
@davidwengier davidwengier modified the milestones: Next, 18.4 Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IDE0370 false positive, when initializing auto-property with null!.

4 participants