Skip to content

DocumentationCommentId.GetSymbolsForDeclarationId doesn't work with method declared in extension #78606

@meziantou

Description

@meziantou

Version Used: 4.14.0

Steps to Reproduce:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>  
  <ItemGroup>
    <PackageReference Include="Basic.Reference.Assemblies.NetStandard20" Version="1.8.0" />
    <PackageReference Include="Microsoft.CodeAnalysis" Version="4.14.0" PrivateAssets="all" />
  </ItemGroup>
</Project>
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;

var options = new CSharpParseOptions(LanguageVersion.Preview);
var syntaxTree = CSharpSyntaxTree.ParseText("""
    static partial class Dummy
    {
        extension(string target)
        {
            public void Foo()
            {
            }
        }
    }
    """, options);

var compilation = CSharpCompilation.Create("dummy", [syntaxTree], Basic.Reference.Assemblies.NetStandard20.References.All);

var symbol = compilation.GetSymbolsWithName("Foo").Single();

// id is empty ("")
var id = DocumentationCommentId.CreateReferenceId(symbol);

// result is null
var result = DocumentationCommentId.GetFirstSymbolForDeclarationId("Dummy.Foo()", compilation);

Expected Behavior:

  • DocumentationCommentId.CreateReferenceId should return a non-empty string
  • DocumentationCommentId.GetFirstSymbolForDeclarationId should return a symbol

Actual Behavior:

  • DocumentationCommentId.CreateReferenceId returns an empty string
  • DocumentationCommentId.GetFirstSymbolForDeclarationId returns null

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions