Skip to content

Extract local function refactoring generates incorrect code for generic methods #81789

@MaceWindu

Description

@MaceWindu

Version Used:
VS: 18.1.1
C# Tools: 5.0.0-2.25574.6+7f327e02b43a2486faa9cfdf0a1eae34c06e2d1a

Steps to Reproduce:

Use extract local function refactoring on method body

public class Class1
{
    public static List<T> CreateList<T>()
        where T : class
    {
        return new List<T>();
    }
}

Expected Behavior:

public class Class1
{
    public static List<T> CreateList<T>()
        where T : class
    {
        return NewMethod();

        static List<T> NewMethod()
        {
            return new List<T>();
        }
    }
}

Actual Behavior:

public class Class1
{
    public static List<T> CreateList<T>()
        where T : class
    {
        return NewMethod<T>();

        // CS8387: Type parameter 'T' has the same name as the type parameter from outer method 'Class1.CreateList<T>()'
        static List<T> NewMethod<T>() where T : class
        {
            return new List<T>();
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions