Skip to content

"Extract Method" introduces an invalid nullability annotation that results in a nullability issue in the extracted code #61555

@Tragetaschen

Description

@Tragetaschen

Version Used:

17.3.0 Preview 1.1

Steps to Reproduce:

public class C
{
    public void M(C? c)
    {
        if (c == null)
        {
            return;
        }

        c.ToString(); // <-- extract this
    }
}

Run "Extract Method" on the c.ToString(); line.

Expected Behavior:

The method parameter of the extracted method should be NewMethod(C c).

Actual Behavior:

The method parameter of the extracted method is NewMethod(C? c) with a nullable annotation. This then results in a nullability warning in the extracted code, because the null check is not in scope anymore.

image

This is likely related to #60552

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Completed

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions