From 3e27f81541e825b3e3e8de96bd765270307a4e71 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 12 May 2022 13:40:12 -0700 Subject: [PATCH 1/3] Relax assertion in SyntheticBoundNodeFactory.Convert --- .../Lowering/SyntheticBoundNodeFactory.cs | 2 +- .../Semantic/Semantics/ColorColorTests.cs | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs index 0bb67f8d7d8e7..0fbc647a96652 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs @@ -1298,7 +1298,7 @@ public BoundExpression Convert(TypeSymbol type, BoundExpression arg) #endif Conversion c = Compilation.Conversions.ClassifyConversionFromExpression(arg, type, isChecked: false, ref useSiteInfo); Debug.Assert(c.Exists); - Debug.Assert(useSiteInfo.Diagnostics.IsNullOrEmpty()); + Debug.Assert(!useSiteInfo.HasErrors); return Convert(type, arg, c); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs index 4cb4007004d61..470dc940625fd 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs @@ -2117,6 +2117,45 @@ void F() main.VerifyEmitDiagnostics(unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning); } + [Fact, WorkItem(61284, "https://github.com/dotnet/roslyn/issues/61284")] + public void PatternMatchToBaseTypeWithUseSiteWarningOnBaseType() + { + string sourceRefLib = @" +public class Base { } +"; + + var refLib = CreateEmptyCompilation( + sourceRefLib, + assemblyName: "RefLib", + references: new[] { TestMetadata.Net20.mscorlib }); + + refLib.VerifyEmitDiagnostics(); + + string sourceMain = @" +public class Derived : Base { } +class C +{ + void M(Derived d) + { + _ = d is Base b; + } +} +"; + + var main = CreateEmptyCompilation(sourceMain, assemblyName: "Main", + references: new MetadataReference[] + { + new CSharpCompilationReference(refLib), + TestMetadata.Net451.mscorlib + }); + + var unifyReferenceWarning = + // warning CS1701: Assuming assembly reference 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'RefLib' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy + Diagnostic(ErrorCode.WRN_UnifyReferenceMajMin).WithArguments("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "RefLib", "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "mscorlib"); + + main.VerifyEmitDiagnostics(unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning, unifyReferenceWarning); + } + [WorkItem(19458, "https://github.com/dotnet/roslyn/issues/19458")] [Fact] public void ObsoleteConstColorColorEnum() From 6181e5e5945982afb48b8fa8b68a68a8abeb60e2 Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 12 May 2022 13:53:26 -0700 Subject: [PATCH 2/3] Unskip test --- src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs index f872c316c1810..97ddce1d7134f 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs @@ -30313,7 +30313,7 @@ class C2 : I(0) ); } - [ConditionalTheory(typeof(NoUsedAssembliesValidation), Reason = "https://github.com/dotnet/roslyn/issues/60060")] + [Theory] [WorkItem(44902, "https://github.com/dotnet/roslyn/issues/44902")] [CombinatorialData] public void CrossAssemblySupportingAndNotSupportingCovariantReturns(bool useCompilationReference) @@ -30326,7 +30326,7 @@ public void CrossAssemblySupportingAndNotSupportingCovariantReturns(bool useComp public record C(int I) : B(I);"; var compA = CreateEmptyCompilation(new[] { sourceA, IsExternalInitTypeDefinition }, references: TargetFrameworkUtil.GetReferences(TargetFramework.NetStandard20)); - compA.VerifyDiagnostics(); + compA.VerifyEmitDiagnostics(); Assert.False(compA.Assembly.RuntimeSupportsCovariantReturnsOfClasses); var actualMembers = compA.GetMember("C").GetMembers().ToTestDisplayStrings(); var expectedMembers = new[] @@ -30354,7 +30354,7 @@ public record C(int I) : B(I);"; // CS1701: Assuming assembly reference '{0}' used by '{1}' matches identity '{2}' of '{3}', you may need to supply runtime policy var compB = CreateCompilation(sourceB, references: new[] { refA }, options: TestOptions.ReleaseDll.WithSpecificDiagnosticOptions("CS1701", ReportDiagnostic.Suppress), parseOptions: TestOptions.Regular9, targetFramework: TargetFramework.NetCoreApp); - compB.VerifyDiagnostics(); + compB.VerifyEmitDiagnostics(); Assert.True(compB.Assembly.RuntimeSupportsCovariantReturnsOfClasses); actualMembers = compB.GetMember("D").GetMembers().ToTestDisplayStrings(); From 31323f1812dd4766f239e79a1434f94d88e35b1e Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Thu, 12 May 2022 16:17:05 -0700 Subject: [PATCH 3/3] Add comment --- .../CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs index 0fbc647a96652..0e80a7df79155 100644 --- a/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs +++ b/src/Compilers/CSharp/Portable/Lowering/SyntheticBoundNodeFactory.cs @@ -1298,6 +1298,7 @@ public BoundExpression Convert(TypeSymbol type, BoundExpression arg) #endif Conversion c = Compilation.Conversions.ClassifyConversionFromExpression(arg, type, isChecked: false, ref useSiteInfo); Debug.Assert(c.Exists); + // The use-site diagnostics should be reported earlier, and we shouldn't get to lowering if they're errors. Debug.Assert(!useSiteInfo.HasErrors); return Convert(type, arg, c);