Skip to content

Expression bodied method whose expression is a switch expression is missing debug info #37261

@tmat

Description

@tmat
using System;
public class C
{
    static int M() => F() switch
    {
        1 => 1,
        C { P: int p, Q: C { P: int q } } => G(() => p + q),
        _ => 0
    };

    object P { get; set; }
    object Q { get; set; }
    static object F() => null;
    static int G(Func<int> f) => 0;
}

Produces no debug info for method C.M (specifically, no sequence points).

Analysis:

ILBuilder.AllocateILMarker creates 2 ILMarkers, both at BlockOffset = 0: one user-code sequence point and another hidden one.
RealizeSequencePoints uses the last defined sequence point for the offset (the hidden one).
SequencePointList.GetSequencePoints then emits no sequence points since the only sequence point in the list is hidden.

The issue is with the hidden sequence point emitted for the switch expression closure.

See PDBTests.SwitchExpression_MethodBody.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions