Skip to content
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

Add support for adding null checks to records. #59404

Merged
merged 1 commit into from Feb 9, 2022

Conversation

CyrusNajmabadi
Copy link
Member

Fixes #58779

@@ -29,18 +29,27 @@ internal abstract partial class AbstractInitializeParameterCodeRefactoringProvid
where TStatementSyntax : SyntaxNode
where TExpressionSyntax : SyntaxNode
{
private readonly Func<SyntaxNode, bool> _isFunctionDeclarationFunc;
protected readonly Func<SyntaxNode, bool> _isFunctionDeclarationFunc;
protected readonly Func<SyntaxNode, bool> _isRecordDeclarationFunc;
Copy link
Contributor

Choose a reason for hiding this comment

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

With the compiler change about caching method groups, do we need to bother with the protected fields any more, versus just referencing the methods directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a static method, so we'd still need this manual caching

@CyrusNajmabadi CyrusNajmabadi merged commit 82094cf into dotnet:main Feb 9, 2022
@ghost ghost added this to the Next milestone Feb 9, 2022
protected override ISyntaxFacts SyntaxFacts
=> CSharpSyntaxFacts.Instance;

protected override bool SupportsRecords(ParseOptions options)
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't understand this bit. It seems like a primary constructor parameter is perfectly valid to use to initialize a member. It just has to be in a field initializer. Maybe the refactoring isn't intended for that scenario?

record Rec(int X)
{
    public int X; // can offer `= X;` refactoring here?
}

@RikkiGibson RikkiGibson modified the milestones: Next, 17.2.P2 Mar 1, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the recordNullCheck branch March 2, 2022 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add parameter null check refactoring doesn't work on record primary constructors
3 participants