提交 9f3fc259 编写于 作者: J Julien 提交者: GitHub

Treat tuple type as a struct if underlying type is error type (#13258)

上级 eb4e2880
......@@ -668,7 +668,7 @@ public override bool IsValueType
{
get
{
return _underlyingType.IsValueType;
return _underlyingType.IsErrorType() || _underlyingType.IsValueType;
}
}
......
......@@ -17525,20 +17525,6 @@ public struct S
);
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/13088")]
public void AssignNullWithMissingValueTuple()
{
var source = @"
public struct S
{
(int, int) t = null;
}
";
var comp = CreateCompilationWithMscorlib(source);
comp.VerifyDiagnostics(); // crashes
}
[Fact]
public void RetargetTupleErrorType()
{
......@@ -17571,5 +17557,80 @@ public class B
Assert.False(methodM.ReturnType.IsErrorType());
Assert.True(methodM.ReturnType.TupleUnderlyingType.IsErrorType());
}
[Fact, WorkItem(13088, "https://github.com/dotnet/roslyn/issues/13088")]
public void AssignNullWithMissingValueTuple()
{
var source = @"
public class S
{
(int, int) t = null;
}
";
var comp = CreateCompilationWithMscorlib(source);
comp.VerifyDiagnostics(
// (4,5): error CS0518: Predefined type 'System.ValueTuple`2' is not defined or imported
// (int, int) t = null;
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int, int)").WithArguments("System.ValueTuple`2").WithLocation(4, 5),
// (4,20): error CS0037: Cannot convert null to '(int, int)' because it is a non-nullable value type
// (int, int) t = null;
Diagnostic(ErrorCode.ERR_ValueCantBeNull, "null").WithArguments("(int, int)").WithLocation(4, 20)
);
}
[Fact, WorkItem(11302, "https://github.com/dotnet/roslyn/issues/11302")]
public void CrashInVisitCallReceiverOnBadTupleSyntax()
{
var source1 = @"
public static class C1
{
public void M1(this int x, (int, int)))
{
System.Console.WriteLine(""M1"");
}
}
" + trivial2uple;
var source2 = @"
public static class C2
{
public void M1(this int x, (int, int)))
{
System.Console.WriteLine(""M1"");
}
}
" + trivial2uple;
var comp1 = CreateCompilationWithMscorlibAndSystemCore(source1, assemblyName: "comp1",
parseOptions: TestOptions.Regular.WithTuplesFeature());
var comp2 = CreateCompilationWithMscorlibAndSystemCore(source2, assemblyName: "comp2",
parseOptions: TestOptions.Regular.WithTuplesFeature());
var source = @"
class C3
{
public static void Main()
{
int x = 0;
x.M1((1, 1));
}
}
";
var comp = CreateCompilationWithMscorlib(source,
references: new[] { comp1.ToMetadataReference(), comp2.ToMetadataReference() },
parseOptions: TestOptions.Regular.WithTuplesFeature(),
options: TestOptions.DebugExe);
comp.VerifyDiagnostics(
// (7,14): error CS0518: Predefined type 'System.ValueTuple`2' is not defined or imported
// x.M1((1, 1));
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(1, 1)").WithArguments("System.ValueTuple`2").WithLocation(7, 14),
// (7,11): error CS0121: The call is ambiguous between the following methods or properties: 'C1.M1(int, (int, int))' and 'C2.M1(int, (int, int))'
// x.M1((1, 1));
Diagnostic(ErrorCode.ERR_AmbigCall, "M1").WithArguments("C1.M1(int, (int, int))", "C2.M1(int, (int, int))").WithLocation(7, 11)
);
}
}
}
......@@ -2303,5 +2303,34 @@ static void Main()
Diagnostic(ErrorCode.ERR_VariableUsedBeforeDeclaration, "x1").WithArguments("x1").WithLocation(6, 42)
);
}
[Fact, WorkItem(13081, "https://github.com/dotnet/roslyn/issues/13081")]
public void GettingDiagnosticsWhenValueTupleIsMissing()
{
var source = @"
class C1
{
static void Test(int arg1, (byte, byte) arg2)
{
foreach ((int, int) e in new (int, int)[10])
{
}
}
}
";
var comp = CreateCompilationWithMscorlib(source);
comp.VerifyDiagnostics(
// (4,32): error CS0518: Predefined type 'System.ValueTuple`2' is not defined or imported
// static void Test(int arg1, (byte, byte) arg2)
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(byte, byte)").WithArguments("System.ValueTuple`2").WithLocation(4, 32),
// (6,38): error CS0518: Predefined type 'System.ValueTuple`2' is not defined or imported
// foreach ((int, int) e in new (int, int)[10])
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int, int)").WithArguments("System.ValueTuple`2").WithLocation(6, 38),
// (6,18): error CS0518: Predefined type 'System.ValueTuple`2' is not defined or imported
// foreach ((int, int) e in new (int, int)[10])
Diagnostic(ErrorCode.ERR_PredefinedTypeNotFound, "(int, int)").WithArguments("System.ValueTuple`2").WithLocation(6, 18)
);
// no crash
}
}
}
......@@ -1506,7 +1506,7 @@ public void TestDeconstruction()
var expectedDiagnostics = new[]
{
// (8,12): error CS1768: Type 'ValueTuple<T1, T2>' cannot be embedded because it has a generic argument. Consider setting the 'Embed Interop Types' property to false.
// (8,12): error CS1768: Type 'ValueTuple<T1, T2>' cannot be embedded because it has a generic argument. Consider setting the 'Embed Interop Types' property to false.
// public (int, int) TestTuple()
Diagnostic(ErrorCode.ERR_GenericsUsedInNoPIAType, "(int, int)").WithArguments("System.ValueTuple<T1, T2>").WithLocation(8, 12),
// (4,19): error CS1768: Type 'ValueTuple<T1, T2>' cannot be embedded because it has a generic argument. Consider setting the 'Embed Interop Types' property to false.
......@@ -1514,7 +1514,10 @@ public void TestDeconstruction()
Diagnostic(ErrorCode.ERR_GenericsUsedInNoPIAType, "ValueTuple<string, string>").WithArguments("System.ValueTuple<T1, T2>").WithLocation(4, 19),
// (14,16): error CS1768: Type 'ValueTuple<T1, T2>' cannot be embedded because it has a generic argument. Consider setting the 'Embed Interop Types' property to false.
// return (1, 2);
Diagnostic(ErrorCode.ERR_GenericsUsedInNoPIAType, "(1, 2)").WithArguments("System.ValueTuple<T1, T2>").WithLocation(14, 16)
Diagnostic(ErrorCode.ERR_GenericsUsedInNoPIAType, "(1, 2)").WithArguments("System.ValueTuple<T1, T2>").WithLocation(14, 16),
// (19,9): error CS1768: Type 'ValueTuple<T1, T2>' cannot be embedded because it has a generic argument. Consider setting the 'Embed Interop Types' property to false.
// (x, y) = new C();
Diagnostic(ErrorCode.ERR_GenericsUsedInNoPIAType, "(x, y) = new C()").WithArguments("System.ValueTuple<T1, T2>").WithLocation(19, 9)
};
var comp1 = CreateCompilationWithMscorlib(source, options: TestOptions.ReleaseDll,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册