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

Problem with float #66

Closed p-bojkowski closed 3 years ago

p-bojkowski commented 3 years ago

Hi!

I found an issue with float. In some cases "F" is missing:

new System.Drawing.Font("Calibri", 99.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

result:

CompilationUnit()
.WithMembers(
    SingletonList<MemberDeclarationSyntax>(
        GlobalStatement(
            ExpressionStatement(
                ObjectCreationExpression(
                    QualifiedName(
                        QualifiedName(
                            IdentifierName("System"),
                            IdentifierName("Drawing")),
                        IdentifierName("Font")))
                .WithArgumentList(
                    ArgumentList(
                        SeparatedList<ArgumentSyntax>(
                            new SyntaxNodeOrToken[]{
                                Argument(
                                    LiteralExpression(
                                        SyntaxKind.StringLiteralExpression,
                                        Literal("Calibri"))),
                                Token(SyntaxKind.CommaToken),
                                Argument(
                                    LiteralExpression(
                                        SyntaxKind.NumericLiteralExpression,
                                        Literal(99.75))),
                                Token(SyntaxKind.CommaToken),
                                Argument(
                                    MemberAccessExpression(
                                        SyntaxKind.SimpleMemberAccessExpression,
                                        MemberAccessExpression(
                                            SyntaxKind.SimpleMemberAccessExpression,
                                            MemberAccessExpression(
                                                SyntaxKind.SimpleMemberAccessExpression,
                                                IdentifierName("System"),
                                                IdentifierName("Drawing")),
                                            IdentifierName("FontStyle")),
                                        IdentifierName("Regular"))),
                                Token(SyntaxKind.CommaToken),
                                Argument(
                                    MemberAccessExpression(
                                        SyntaxKind.SimpleMemberAccessExpression,
                                        MemberAccessExpression(
                                            SyntaxKind.SimpleMemberAccessExpression,
                                            MemberAccessExpression(
                                                SyntaxKind.SimpleMemberAccessExpression,
                                                IdentifierName("System"),
                                                IdentifierName("Drawing")),
                                            IdentifierName("GraphicsUnit")),
                                        IdentifierName("Point")))})))))))
.NormalizeWhitespace()

The "F" for 99.75F is missing:

new System.Drawing.Font("Calibri", 99.75, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

And this will not compile.

But:

float f = 99.75F;

result:

CompilationUnit()
.WithMembers(
    SingletonList<MemberDeclarationSyntax>(
        GlobalStatement(
            LocalDeclarationStatement(
                VariableDeclaration(
                    PredefinedType(
                        Token(SyntaxKind.FloatKeyword)))
                .WithVariables(
                    SingletonSeparatedList<VariableDeclaratorSyntax>(
                        VariableDeclarator(
                            Identifier("f"))
                        .WithInitializer(
                            EqualsValueClause(
                                LiteralExpression(
                                    SyntaxKind.NumericLiteralExpression,
                                    Literal(99.75))))))))))
.NormalizeWhitespace()

"F" -> Identifier("f")

p-bojkowski commented 3 years ago

thx @KirillOsenkov !!! :)