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

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

Open
Tragetaschen opened this issue May 27, 2022 · 0 comments
Labels
Area-IDE Concept-Continuous Improvement Feature - Extract Method help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Milestone

Comments

@Tragetaschen
Copy link

Tragetaschen commented May 27, 2022

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

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 27, 2022
@vatsalyaagrawal vatsalyaagrawal added Concept-Continuous Improvement help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 2, 2022
@vatsalyaagrawal vatsalyaagrawal added this to InQueue in Small Fixes via automation Jun 2, 2022
@vatsalyaagrawal vatsalyaagrawal added this to the Backlog milestone Jun 2, 2022
@vatsalyaagrawal vatsalyaagrawal moved this from InQueue to CodeFix/Refactoring Improvements in Small Fixes Jun 2, 2022
ryzngard added a commit that referenced this issue Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Concept-Continuous Improvement Feature - Extract Method help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Small Fixes
  
CodeFix/Refactoring Improvements
Development

No branches or pull requests

2 participants