Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relax assertion in SyntheticBoundNodeFactory.Convert #61287

Merged
merged 3 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,8 @@ 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());
// 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);
Copy link
Member

@cston cston May 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert

Are we dropping use-site warnings in cases where the previous assertion failed? (It looks like the warnings are reported from the two tests. Are the warnings reported from within this method?)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Convert method doesn't report those use-site diagnostics (we use DiscardedDependencies/Discarded above).
In both scenarios, the use-site warnings are reported elsewhere.

}
Expand Down
39 changes: 39 additions & 0 deletions src/Compilers/CSharp/Test/Semantic/Semantics/ColorColorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions src/Compilers/CSharp/Test/Semantic/Semantics/RecordTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<NamedTypeSymbol>("C").GetMembers().ToTestDisplayStrings();
var expectedMembers = new[]
Expand Down Expand Up @@ -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<NamedTypeSymbol>("D").GetMembers().ToTestDisplayStrings();
Expand Down