From b59f625085e9d05055b99a03571792216f64e769 Mon Sep 17 00:00:00 2001 From: Chris Sienkiewicz Date: Wed, 12 Jun 2019 11:56:28 -0700 Subject: [PATCH] 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 --- .../Portable/FlowAnalysis/NullableWalker.cs | 4 ++-- .../Semantics/NullableReferenceTypesTests.cs | 17 +++++++++++++++-- .../NameTupleElement/NameTupleElementTests.cs | 4 +++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index 3a8d05bf62d..080982a0117 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -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); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 86081cb4c5d..f65d407093d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -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] diff --git a/src/EditorFeatures/CSharpTest/NameTupleElement/NameTupleElementTests.cs b/src/EditorFeatures/CSharpTest/NameTupleElement/NameTupleElementTests.cs index 3d79f05afae..186168c736d 100644 --- a/src/EditorFeatures/CSharpTest/NameTupleElement/NameTupleElementTests.cs +++ b/src/EditorFeatures/CSharpTest/NameTupleElement/NameTupleElementTests.cs @@ -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( -- GitLab