diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index 1368dd3181bebf1fdbd012dd6d4503536316864d..ef1fd3a6877a8e852fcdb5f1fe94035f94506b36 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -18098,5 +18098,40 @@ static void Main() }); // no assertion in MetadataWriter } + + [Fact] + [WorkItem(13661, "https://github.com/dotnet/roslyn/issues/13661")] + public void LongTupleWithPartialNames_Bug13661() + { + var source = @" +using System; +class C +{ + static void Main() + { + var o = (A: 1, 2, C: 3, D: 4, E: 5, F: 6, G: 7, 8, I: 9); + Console.Write(o.I); + } +} +"; + CompileAndVerify(source, + additionalRefs: s_valueTupleRefs, + options: TestOptions.DebugExe, + expectedOutput: @"9", + sourceSymbolValidator: (module) => + { + var sourceModule = (SourceModuleSymbol)module; + var compilation = sourceModule.DeclaringCompilation; + var tree = compilation.SyntaxTrees.First(); + var model = compilation.GetSemanticModel(tree); + var nodes = tree.GetCompilationUnitRoot().DescendantNodes(); + + var x = nodes.OfType().First(); + var xSymbol = ((SourceLocalSymbol)model.GetDeclaredSymbol(x)).Type; + AssertEx.SetEqual(xSymbol.GetMembers().OfType().Select(f => f.Name), + "A", "C", "D", "E", "F", "G", "I", "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Rest"); + }); + // no assert hit + } } } \ No newline at end of file diff --git a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb index 38d5666261f11a5c8bd3268550da34adfd990c61..60a2e37137c39bd8440ba4dd9966cebd3b15f8d7 100644 --- a/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb +++ b/src/Compilers/VisualBasic/Test/Emit/CodeGen/CodeGenTuples.vb @@ -8198,6 +8198,40 @@ End Module End Sub + + + Public Sub LongTupleWithPartialNames_Bug13661() + + Dim verifier = CompileAndVerify( + + +Module C + Sub Main() + Dim t = (A:=1, 2, C:=3, D:=4, E:=5, F:=6, G:=7, 8, I:=9) + System.Console.Write($"{t.I}") + End Sub +End Module + + +, additionalRefs:={ValueTupleRef, SystemRuntimeFacadeRef}, + options:=TestOptions.DebugExe, expectedOutput:="9", + sourceSymbolValidator:= + Sub(m As ModuleSymbol) + Dim compilation = m.DeclaringCompilation + Dim tree = compilation.SyntaxTrees.First() + Dim model = compilation.GetSemanticModel(tree) + Dim nodes = tree.GetCompilationUnitRoot().DescendantNodes() + + Dim t = nodes.OfType(Of VariableDeclaratorSyntax)().Single().Names(0) + Dim xSymbol = DirectCast(model.GetDeclaredSymbol(t), LocalSymbol).Type + + AssertEx.SetEqual(xSymbol.GetMembers().OfType(Of FieldSymbol)().Select(Function(f) f.Name), + "A", "C", "D", "E", "F", "G", "I", "Item1", "Item2", "Item3", "Item4", "Item5", "Item6", "Item7", "Item8", "Item9", "Rest") + End Sub) + ' No assert hit + + End Sub + End Class End Namespace diff --git a/src/EditorFeatures/CSharpTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs b/src/EditorFeatures/CSharpTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs index 488becff63ce19bfc03f25ffd822e2506d166486..74e403911d84715a1d9d8eaf2fdac3752a17fa8b 100644 --- a/src/EditorFeatures/CSharpTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs +++ b/src/EditorFeatures/CSharpTest/CodeActions/InlineTemporary/InlineTemporaryTests.cs @@ -4071,5 +4071,47 @@ public void M() await TestAsync(code, expected, index: 0); } + + [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsInlineTemporary)] + [WorkItem(12802, "https://github.com/dotnet/roslyn/issues/12802")] + public async Task Deconstruction2() + { + var code = @" +class Program +{ + static void Main() + { + var [||]kvp = KVP.Create(42, ""hello""); + var(x1, x2) = kvp; + } +} +public static class KVP +{ + public static KVP Create(T1 item1, T2 item2) { return null; } +} +public class KVP +{ + public void Deconstruct(out T1 item1, out T2 item2) { item1 = default(T1); item2 = default(T2); } +}"; + + var expected = @" +class Program +{ + static void Main() + { + var(x1, x2) = KVP.Create(42, ""hello""); + } +} +public static class KVP +{ + public static KVP Create(T1 item1, T2 item2) { return null; } +} +public class KVP +{ + public void Deconstruct(out T1 item1, out T2 item2) { item1 = default(T1); item2 = default(T2); } +}"; + + await TestAsync(code, expected, index: 0); + } } }