Skip to content

Commit d92fd99

Browse files
authored
Handle extension blocks in CLS compliance checker (#80251)
1 parent e3cf188 commit d92fd99

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Compilers/CSharp/Portable/Compiler/ClsComplianceChecker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ private void CheckBaseTypeCompliance(NamedTypeSymbol symbol)
529529
else
530530
{
531531
NamedTypeSymbol baseType = symbol.EnumUnderlyingType ?? symbol.BaseTypeNoUseSiteDiagnostics; // null for interfaces
532-
System.Diagnostics.Debug.Assert((object)baseType != null || symbol.SpecialType == SpecialType.System_Object, "Only object has no base.");
532+
System.Diagnostics.Debug.Assert((object)baseType != null || symbol.SpecialType == SpecialType.System_Object || symbol.IsExtension, "Only object or extension has no base.");
533533
if ((object)baseType != null && !IsCompliantType(baseType, symbol))
534534
{
535535
// TODO: it would be nice to report this on the base type clause.

src/Compilers/CSharp/Test/Emit3/Semantics/ExtensionTests2.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,19 @@ static void local<U>(U u, System.Linq.Expressions.Expression<System.Func<U, obje
769769
CompileAndVerify(comp, expectedOutput: ExpectedOutput("{ A = 43 }"), verify: Verification.Skipped).VerifyDiagnostics();
770770
}
771771

772+
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/80250")]
773+
public void Cls()
774+
{
775+
var src = """
776+
[assembly: System.CLSCompliant(true)]
777+
public static class Extensions
778+
{
779+
extension(object) { }
780+
}
781+
""";
782+
CreateCompilation(src).VerifyEmitDiagnostics();
783+
}
784+
772785
[Fact]
773786
public void Attribute_01()
774787
{

0 commit comments

Comments
 (0)