Skip to content

Fix not offering to remove unnecessary nullable pragmas#79356

Merged
CyrusNajmabadi merged 1 commit intodotnet:mainfrom
CyrusNajmabadi:unnecessaryNullableWithAttribute
Jul 14, 2025
Merged

Fix not offering to remove unnecessary nullable pragmas#79356
CyrusNajmabadi merged 1 commit intodotnet:mainfrom
CyrusNajmabadi:unnecessaryNullableWithAttribute

Conversation

@CyrusNajmabadi
Copy link
Contributor

Fixes #65401

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 13, 2025 19:18
}

// An attribute name cannot itself be nullable. `[CLSCompliant?]` is not a thing.
if (node.IsParentKind(SyntaxKind.Attribute))
Copy link
Contributor

Choose a reason for hiding this comment

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

An attribute can have a constructor parameter/property initializer, which can lead to warnings after nullable directive removed, e.g. [MyAttr(null, Prop = null)] with MyAttr declared as

#nullable enable

class MyAttr : Attribute
{
    public object Prop { get; set; }

    public MyAttr(string s) { }
}

Does this change account for that? Add test cases for this

@CyrusNajmabadi CyrusNajmabadi merged commit c2a8957 into dotnet:main Jul 14, 2025
26 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the unnecessaryNullableWithAttribute branch July 14, 2025 17:02
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jul 14, 2025
@RikkiGibson RikkiGibson modified the milestones: Next, 18.0 P1 Aug 19, 2025
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.

IDE0241 is not reported when found attribute

4 participants