diff --git a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs index 09de5be4eb82478d52759beb3f3394bdc6ac2ebf..a99d0900eabd495b318371ccceddf2704d48c6bb 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/PDBTests.cs @@ -2657,6 +2657,142 @@ static void Main(string[] args) " ); } + + [Fact] + public void ForEachStatement_Deconstruction() + { + var source = @" +public class C +{ + public static (int, (bool, double))[] F() => new[] { (1, (true, 2.0)) }; + + public static void Main() + { + foreach (var (c, (d, e)) in F()) + { + System.Console.WriteLine(c); + } + } +} +"; + var c = CreateStandardCompilation(source, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, options: TestOptions.DebugDll); + var v = CompileAndVerify(c); + + v.VerifyIL("C.Main", @" +{ + // Code size 72 (0x48) + .maxstack 2 + .locals init ((int, (bool, double))[] V_0, + int V_1, + int V_2, //c + bool V_3, //d + double V_4, //e + System.ValueTuple V_5) + // sequence point: { + IL_0000: nop + // sequence point: foreach + IL_0001: nop + // sequence point: F() + IL_0002: call ""(int, (bool, double))[] C.F()"" + IL_0007: stloc.0 + IL_0008: ldc.i4.0 + IL_0009: stloc.1 + // sequence point: + IL_000a: br.s IL_0041 + // sequence point: var (c, (d, e)) + IL_000c: ldloc.0 + IL_000d: ldloc.1 + IL_000e: ldelem ""System.ValueTuple"" + IL_0013: dup + IL_0014: ldfld ""(bool, double) System.ValueTuple.Item2"" + IL_0019: stloc.s V_5 + IL_001b: dup + IL_001c: ldfld ""int System.ValueTuple.Item1"" + IL_0021: stloc.2 + IL_0022: ldloc.s V_5 + IL_0024: ldfld ""bool System.ValueTuple.Item1"" + IL_0029: stloc.3 + IL_002a: ldloc.s V_5 + IL_002c: ldfld ""double System.ValueTuple.Item2"" + IL_0031: stloc.s V_4 + IL_0033: pop + // sequence point: { + IL_0034: nop + // sequence point: System.Console.WriteLine(c); + IL_0035: ldloc.2 + IL_0036: call ""void System.Console.WriteLine(int)"" + IL_003b: nop + // sequence point: } + IL_003c: nop + // sequence point: + IL_003d: ldloc.1 + IL_003e: ldc.i4.1 + IL_003f: add + IL_0040: stloc.1 + // sequence point: in + IL_0041: ldloc.1 + IL_0042: ldloc.0 + IL_0043: ldlen + IL_0044: conv.i4 + IL_0045: blt.s IL_000c + // sequence point: } + IL_0047: ret +} +", sequencePoints: "C.Main", source: source); + + v.VerifyPdb(@" + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"); + } + + #endregion + + #region Switch [Fact] public void SwitchWithPattern_01() @@ -2843,6 +2979,7 @@ class Student : Person { public double GPA; } " ); } + #endregion #region DoStatement diff --git a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs index c933b603d575773a5e6ee7bf4bb4a62ef3d72039..dd41414e39b7580d236af3424829878fa16dc03c 100644 --- a/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs +++ b/src/ExpressionEvaluator/CSharp/Test/ExpressionCompiler/LocalsTests.cs @@ -1452,6 +1452,28 @@ .maxstack 1 }); } + [Fact(Skip = "18273"), WorkItem(18273, "https://github.com/dotnet/roslyn/issues/18273")] + public void CapturedLocalInNestedLambda() + { + var source = @" +using System; + +class C +{ + void M() { } +}"; + var compilation0 = CreateStandardCompilation(source, options: TestOptions.DebugDll); + WithRuntimeInstance(compilation0, runtime => + { + var context = CreateMethodContext(runtime, "C.M"); + + var testData = new CompilationTestData(); + context.CompileExpression("new Action(() => { int x; new Func(() => x).Invoke(); }).Invoke()", out var error, testData); + Assert.Null(error); + testData.GetMethodData("<>x.<>m0").VerifyIL(""); + }); + } + [Fact] public void NestedLambdas() {