Skip to content

Add parameter null check refactoring doesn't work on record primary constructors #58779

@RikkiGibson

Description

@RikkiGibson

Version Used: 59c9b29

Steps to Reproduce:

        [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInitializeParameter)]
        public async Task TestRecordPrimaryConstructor()
        {
            // https://github.com/dotnet/roslyn/issues/58779
            // Note: we declare a field within the record to work around missing IsExternalInit errors
            await new VerifyCS.Test
            {
                LanguageVersion = LanguageVersionExtensions.CSharpNext,
                TestCode = @"
using System;

record Rec([||]string s) { public string s = s; }
",
                FixedCode = @"
using System;

record Rec(string s) { public string s = s; }
"
            }.RunAsync();
        }

Expected Behavior: "Add parameter null check" refactoring is offered and places !! on parameter

Actual Behavior: Refactoring is not offered

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions