You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IDE0370 reports field! in a property getter as unnecessary, but removing it causes CS9264 #86573
Build with dotnet_diagnostic.IDE0370.severity = warning: the only diagnostics are IDE0370: Suppression is unnecessary on each field!.
Apply the fix (dotnet format style --diagnostics IDE0370). Each field! becomes field.
Build again.
Expected Behavior: IDE0370 isn't reported, because the ! is what makes the getter null-resilient and suppresses CS9264.
Actual Behavior: after the fix the build gets three new warnings, CS9264: Non-nullable property 'Name' must contain a non-null value when exiting constructor..., on the property in A and on the constructors in B and C. With TreatWarningsAsErrors the build fails.
Cause: the field-keyword proposal says null-forgiving operators are respected when deciding whether the getter is null-resilient. UnnecessaryNullableWarningSuppressionsUtilities re-checks the code without the !, but only keeps diagnostics that intersect the containing member: the accessor for get => field! / get { return field!; }, or the property for string Name => field! (whose diagnostics are computed for the whole type but then filtered to the property's span). CS9264 is reported on the property name or on the constructor, outside those spans, so it's never seen. There are no field keyword cases in the existing tests. #81843 is a different IDE0370 false positive.
Possible fix: when the suppression is in the getter of a property that uses field, check diagnostics across the containing type (including other partial declarations), or don't offer the removal in that case, plus tests. Happy to send a PR if you agree.
Thanks, I'll send a PR along those lines: when the suppression is in the getter of a property that uses field, also check the diagnostics at the property's identifier and at the containing type's constructor identifiers. If a constructor is in another partial declaration (another file), I'll just not offer the removal there.
Activity
CyrusNajmabadi commentedon Nov 22, 2026
yes. we should include the containing property name-span, and the constructor name-span if those are the locations these warnings get emitted.
Manish-1kumar commentedon Nov 22, 2026
Thanks, I'll send a PR along those lines: when the suppression is in the getter of a property that uses
field, also check the diagnostics at the property's identifier and at the containing type's constructor identifiers. If a constructor is in another partial declaration (another file), I'll just not offer the removal there.CyrusNajmabadi commentedon Nov 22, 2026
we can analyze contructors in other parts in other files. it's fine to do that.