Skip to content

Duplicate locals are emitted for switch expression arms #50301

@davidwengier

Description

@davidwengier

See this comment: https://github.com/dotnet/roslyn/pull/50270/files#r552284955

This issue is referenced in source.

For a simple switch expression:

class C
{
    static string M(object o)
    {
        return o switch
        {
            int i => $"Number: {i}",
            _ => "Don't know"
        };
    }
}

There are nested scoped emitted, each with locals that have the same name, for i:

      <scope startOffset="0x0" endOffset="0x3d">
        <scope startOffset="0x1" endOffset="0x3b">
          <local name="i" il_index="0" il_start="0x1" il_end="0x3b" attributes="0" />
          <scope startOffset="0x16" endOffset="0x2b">
            <local name="i" il_index="0" il_start="0x16" il_end="0x2b" attributes="0" />
          </scope>
        </scope>
      </scope>

This also shows up during debugging (note the duplicate is):
image

/cc @tmat @jcouv

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions