Skip to content

Fix not offering to remove unnecessary nullable pragmas #79356

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

Merged

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #65401

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner July 13, 2025 19:18
@@ -97,6 +97,10 @@ private static bool IsLanguageRestrictedToNonNullForm(TypeSyntax node)
return true;
}

// 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
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
3 participants