From 8122d00efc781c9e89e0c495ecd9d934cede0aab Mon Sep 17 00:00:00 2001 From: gafter Date: Fri, 30 Jun 2017 15:43:45 -0700 Subject: [PATCH] Fix one symptom of the non-generic tuple type issue Fixes #20494 Adds a test for #20583 --- .../OverloadResolution/OverloadResolution.cs | 4 +-- .../Test/Emit/CodeGen/CodeGenTupleTest.cs | 32 +++++++++++++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs index 722335a9e7d5c..dda38e3b6c1d0 100644 --- a/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs +++ b/src/Compilers/CSharp/Portable/Binder/Semantics/OverloadResolution/OverloadResolution.cs @@ -1782,8 +1782,8 @@ private static BetterResult MoreSpecificType(TypeSymbol t1, TypeSymbol t2, ref H // argument is more specific and no type argument is less specific than the // corresponding type argument in the other. - var n1 = t1 as NamedTypeSymbol; - var n2 = t2 as NamedTypeSymbol; + var n1 = t1.TupleUnderlyingTypeOrSelf() as NamedTypeSymbol; + var n2 = t2.TupleUnderlyingTypeOrSelf() as NamedTypeSymbol; Debug.Assert(((object)n1 == null) == ((object)n2 == null)); if ((object)n1 == null) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index f58447b58c942..688b3cf2259ca 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -23415,7 +23415,7 @@ void M() [Fact] [WorkItem(20494, "https://github.com/dotnet/roslyn/issues/20494")] - public void MoreGenericTieBreaker() + public void MoreGenericTieBreaker_01() { var source = @"using System; @@ -23436,8 +23436,34 @@ public static void Main() public static void M2(ValueTuple, int> a) { Console.Write(4); } } -public class A { }" + trivial2uple + tupleattributes_cs; - var comp = CompileAndVerify(source, expectedOutput: "24"); +public class A {}"; + var comp = CompileAndVerify(source, additionalRefs: s_valueTupleRefs, expectedOutput: "24"); + } + + [Fact(Skip = "https://github.com/dotnet/roslyn/issues/20583")] + [WorkItem(20494, "https://github.com/dotnet/roslyn/issues/20494")] + [WorkItem(20583, "https://github.com/dotnet/roslyn/issues/20583")] + public void MoreGenericTieBreaker_02() + { + var source = +@"using System; +public class C +{ + public static void Main() + { + // var b = (1, 2, 3, 4, 5, 6, 7, 8); + var b = new ValueTuple>(1, 2, 3, 4, 5, 6, 7, new ValueTuple(8)); + M1(b); + M2(b); // ok, should select M2(ValueTuple> a) + } + public static void M1(ValueTuple a) where TRest : struct { Console.Write(1); } + public static void M2(ValueTuple> a) { Console.Write(2); } + public static void M2(ValueTuple a) where TRest : struct { Console.Write(3); } +} +"; + var comp = CompileAndVerify(source, + additionalRefs: s_valueTupleRefs, + expectedOutput: @"12"); } } }