Skip to content

Unexpected error is reported when an added module contains an extension block #80294

@AlekseyTs

Description

@AlekseyTs
    [Fact]
    public void ExtensionInAddedModule()
    {
        string source = @"
public static class C1
{
    extension(int i)
    {
    }
}
";
        var moduleComp = CreateCompilation(source, options: TestOptions.ReleaseModule);
        var moduleRef = moduleComp.EmitToImageReference();

        CompileAndVerify("", references: [moduleRef]);
    }

Observed:

    Microsoft.CodeAnalysis.Test.Utilities.CompilationVerifier+EmitException : 
    // error CS1569: Error writing to XML documentation file: Unable to cast object of type 'PENamedTypeSymbolNonGeneric' to type 'Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol'.
    Diagnostic(ErrorCode.ERR_DocFileGen).WithArguments("Unable to cast object of type 'PENamedTypeSymbolNonGeneric' to type 'Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol'.").WithLocation(1, 1)

It looks like DocumentationCommentCompiler should be able to handle extensions represented by non-source symbols:

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast object of type 'PENamedTypeSymbolNonGeneric' to type 'Microsoft.CodeAnalysis.CSharp.Symbols.SourceMemberContainerTypeSymbol'.
  Source=Microsoft.CodeAnalysis.CSharp
  StackTrace:
   at Microsoft.CodeAnalysis.CSharp.DocumentationCommentCompiler.<VisitNamedType>g__appendContainedExtensions|17_0(NamedTypeSymbol containingType) in D:\GitHub\roslyn\src\Compilers\CSharp\Portable\Compiler\DocumentationCommentCompiler.cs:line 266

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions