KirillOsenkov / RoslynQuoter

Roslyn tool that for a given C# program shows syntax tree API calls to construct its syntax tree
http://roslynquoter.azurewebsites.net
Apache License 2.0
918 stars 118 forks source link

Records produce incorrect results #57

Closed Youssef1313 closed 3 years ago

Youssef1313 commented 3 years ago

Input:

namespace T
{
    public record X {}
}

Result:

CompilationUnit()
.WithMembers(
    SingletonList<MemberDeclarationSyntax>(
        NamespaceDeclaration(
            IdentifierName("T"))
        .WithMembers(
            SingletonList<MemberDeclarationSyntax>(
                PropertyDeclaration(
                    IdentifierName("record"),
                    Identifier("X"))
                .WithModifiers(
                    TokenList(
                        Token(SyntaxKind.PublicKeyword)))
                .WithAccessorList(
                    AccessorList())))))
.NormalizeWhitespace()

I'm not sure if this issue is on Roslyn's side or not. I have currently some PRs on Roslyn to update things for record's, but not also sure if they will fix that. So opening this so you can give it look.

svick commented 3 years ago

This is because Quoter uses an old version of Roslyn. When I updated it to 3.7.0 (and made few more changes required to make this work), I got:

CompilationUnit()
.WithMembers(
    SingletonList<MemberDeclarationSyntax>(
        NamespaceDeclaration(
            IdentifierName("T"))
        .WithMembers(
            SingletonList<MemberDeclarationSyntax>(
                RecordDeclaration(
                    Token(SyntaxKind.RecordKeyword),
                    Identifier("X"))
                .WithModifiers(
                    TokenList(
                        Token(SyntaxKind.PublicKeyword)))
                .WithOpenBraceToken(
                    Token(SyntaxKind.OpenBraceToken))
                .WithCloseBraceToken(
                    Token(SyntaxKind.CloseBraceToken))))))
.NormalizeWhitespace()

I'm not sure what would be right thing to do here, considering that C# 9.0 is still in preview.

Youssef1313 commented 3 years ago

@svick I think it's reasonable to submit a PR with your changes.

KirillOsenkov commented 3 years ago

Thanks @svick I used your change and updated to 3.8.0-3.final and used the language version Preview to get the latest features.