Skip to content

"Introduce local" in top-level program creates the local at the global scope, breaking references #78875

Open
@jnm2

Description

@jnm2

Version Used: 17.14.4 Preview 1.0

for (var i = 0; i < 10; i++)
{
    Console.Write(args[i]);
}

🪛 "Introduce local for 'args[i]'":

string value = args[i]; // ERROR: 'i' is not in scope here

for (var i = 0; i < 10; i++)
{
    Console.Write(value);
}

If inside a local function, the new local is placed outside the local function:

void M(object[] p)
{
    for (var i = 0; i < 10; i++)
    {
        Console.Write(p[i]);
    }
}

🪛 "Introduce local for 'p[i]'":

object value = p[i]; // ERROR: neither 'p' nor 'i' is in scope here

void M(object[] p)
{
    for (var i = 0; i < 10; i++)
    {
        Console.Write(value);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-IDEhelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on it

    Type

    Projects

    Status

    InQueue

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions