Skip to content

Closure info in PDB is wrong for nested switch expressions #50321

@davidwengier

Description

@davidwengier

From #50270 (comment)

Given nested switch expressions, with lambdas like this:

return o switch
{
    int i => new Func<string>(() => i.ToString() + i switch
    {
        1 => new Func<string>(() => string.Concat(""One"", i))(),
        _ => ""Don't know""
    })(),
    _ => ""Don't know""
};

This emits one closure in the PDB info, starting at the offset for the inner switch keyword.

  <encLambdaMap>
    <methodOrdinal>0</methodOrdinal>
    <closure offset=""174"" />
    <lambda offset=""157"" closure=""0"" />
    <lambda offset=""241"" closure=""0"" />
  </encLambdaMap>

The offsets above are from the test case linked above, which is slightly different, but you can see that the first lambda starts before the closure it is part of, which seems odd to say the least.

/cc @tmat @jcouv

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions