Skip to content

"Introduce parameter for" produces invalid code for nested anonymous type #81013

@jhinder

Description

@jhinder

Version Used: VS 18.0.0 Insiders [11201.2]

Steps to Reproduce:
At the marked location, open the lightbulb menu and select "Introduce parameter for 'a'" > "into extracted method to invoke at callsites".

class C
{
    object M() => new
    {
        $$a = new { },
    };
}

Expected Behavior:
Valid, compilable code is produced.

Actual Behavior:
Uncompilable code is generated:

class C
{
    private global::System.Object GetA() // <- Name is not simplified
    {
        return a; // CS0103: The name 'a' does not exist in the current context
    }

    object M(var a) => new
//           ~~~ CS0825: The contextual keyword 'var' may only appear within a local variable declaration or in script code
    {
        a = new { },
    };
}
Image

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions