未验证 提交 b59f6250 编写于 作者: C Chris Sienkiewicz 提交者: GitHub

Dont try and check tuple conversions in error cases: (#36188)

* Dont try and check tuple conversions in error cases:
- When checking an identity converison, also check for a bound tuple if the type isn't a tuple as we might have a bound tuple with an error type
- When checking a tuple conversion, don't GenerateConversion in the error case as we don't have a target type to generate against
- Update tests
上级 5f528109
......@@ -4447,7 +4447,7 @@ private static BoundConversion GetConversionIfApplicable(BoundExpression convers
return operandType;
}
}
if (operandType.Type?.IsTupleType == true)
if (operandType.Type?.IsTupleType == true || conversionOperand.Kind == BoundKind.TupleLiteral)
{
goto case ConversionKind.ImplicitTuple;
}
......@@ -4550,7 +4550,7 @@ private static BoundConversion GetConversionIfApplicable(BoundExpression convers
}
}
if (checkConversion)
if (checkConversion && !targetType.IsErrorType())
{
// https://github.com/dotnet/roslyn/issues/29699: Report warnings for user-defined conversions on tuple elements.
conversion = GenerateConversion(_conversions, conversionOperand, operandType.Type, targetType, fromExplicitCast, extensionMethodThisArgument);
......
......@@ -51919,7 +51919,8 @@ static void F(object? x, object? y)
Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "t.Rest.Item2").WithLocation(11, 13));
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/35157")]
[Fact]
[WorkItem(35157, "https://github.com/dotnet/roslyn/issues/35157")]
public void TupleTypeInference_08()
{
var source =
......@@ -51929,11 +51930,23 @@ class C
void M()
{
_ = (null, 2);
_ = (null, (2, 3));
_ = (null, (null, (2, 3)));
}
}";
var comp = CreateCompilation(source, options: WithNonNullTypesTrue());
comp.VerifyDiagnostics();
comp.VerifyDiagnostics(
// (6,9): error CS8183: Cannot infer the type of implicitly-typed discard.
// _ = (null, 2);
Diagnostic(ErrorCode.ERR_DiscardTypeInferenceFailed, "_").WithLocation(6, 9),
// (7,9): error CS8183: Cannot infer the type of implicitly-typed discard.
// _ = (null, (2, 3));
Diagnostic(ErrorCode.ERR_DiscardTypeInferenceFailed, "_").WithLocation(7, 9),
// (8,9): error CS8183: Cannot infer the type of implicitly-typed discard.
// _ = (null, (null, (2, 3)));
Diagnostic(ErrorCode.ERR_DiscardTypeInferenceFailed, "_").WithLocation(8, 9)
);
}
[Fact]
......@@ -5,6 +5,7 @@
using Microsoft.CodeAnalysis.CSharp.NameTupleElement;
using Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.CodeRefactorings;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.NameTupleElement
......@@ -85,7 +86,8 @@ public async Task TestInCall_FirstElement_AlreadyNamed()
await TestMissingAsync(@"class C { void M((int arg1, int arg2) x) => M(([||]arg1: 1, 2)); }");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/35157")]
[Fact]
[WorkItem(35157, "https://github.com/dotnet/roslyn/issues/35157")]
public async Task TestUntypedTuple()
{
await TestMissingAsync(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册