Skip to content

Commit

Permalink
Fix one symptom of the non-generic tuple type issue
Browse files Browse the repository at this point in the history
Fixes dotnet#20494
Adds a test for dotnet#20583
  • Loading branch information
gafter committed Jun 30, 2017
1 parent ab2e582 commit 8122d00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
32 changes: 29 additions & 3 deletions src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23436,8 +23436,34 @@ public static void Main()
public static void M2<T>(ValueTuple<ValueTuple<T, int>, int> a) { Console.Write(4); }
}

public class A<T> { }" + trivial2uple + tupleattributes_cs;
var comp = CompileAndVerify(source, expectedOutput: "24");
public class A<T> {}";
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<int, int, int, int, int, int, int, ValueTuple<int>>(1, 2, 3, 4, 5, 6, 7, new ValueTuple<int>(8));
M1(b);
M2(b); // ok, should select M2<T1, T2, T3, T4, T5, T6, T7, T8>(ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>> a)
}
public static void M1<T1, T2, T3, T4, T5, T6, T7, TRest>(ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> a) where TRest : struct { Console.Write(1); }
public static void M2<T1, T2, T3, T4, T5, T6, T7, T8>(ValueTuple<T1, T2, T3, T4, T5, T6, T7, ValueTuple<T8>> a) { Console.Write(2); }
public static void M2<T1, T2, T3, T4, T5, T6, T7, TRest>(ValueTuple<T1, T2, T3, T4, T5, T6, T7, TRest> a) where TRest : struct { Console.Write(3); }
}
";
var comp = CompileAndVerify(source,
additionalRefs: s_valueTupleRefs,
expectedOutput: @"12");
}
}
}

0 comments on commit 8122d00

Please sign in to comment.