-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Numeric literals are not handled properly #35
Comments
Somewhat related issue: dotnet/roslyn#23403. |
To solve this, we need to look at the actual syntax trees for these cases and see how the trees are different. Then make sure that we emit those differences as API calls. There may be another hole where it's impossible to construct the syntax trees using the public API and only the parser is able to construct such trees internally, because it bypasses the public API and uses the internal APIs directly. We've had such cases in the past a few times. |
I suspect that using the |
Aha, so we probably just need to hint it to choose the right overload... |
Could you please check if this is still a problem? |
@KirillOsenkov It's much better, but still not fully fixed. The generated code now is: ArrayCreationExpression(
ArrayType(
PredefinedType(
Token(SyntaxKind.ObjectKeyword)))
.WithRankSpecifiers(
SingletonList<ArrayRankSpecifierSyntax>(
ArrayRankSpecifier(
SingletonSeparatedList<ExpressionSyntax>(
OmittedArraySizeExpression())))))
.WithInitializer(
InitializerExpression(
SyntaxKind.ArrayInitializerExpression,
SeparatedList<ExpressionSyntax>(
new SyntaxNodeOrToken[]{
LiteralExpression(
SyntaxKind.NumericLiteralExpression,
Literal(42)),
Token(SyntaxKind.CommaToken),
LiteralExpression(
SyntaxKind.NumericLiteralExpression,
Literal(42.0)),
Token(SyntaxKind.CommaToken),
LiteralExpression(
SyntaxKind.NumericLiteralExpression,
Literal(42f)),
Token(SyntaxKind.CommaToken),
LiteralExpression(
SyntaxKind.NumericLiteralExpression,
Literal(42m)),
Token(SyntaxKind.CommaToken),
LiteralExpression(
SyntaxKind.NumericLiteralExpression,
Literal(42.0m)),
Token(SyntaxKind.CommaToken),
LiteralExpression(
SyntaxKind.NumericLiteralExpression,
Literal(42.00m))})))
.NormalizeWhitespace() This produces: new object[]{42, 42, 42F, 42M, 42.0M, 42.00M} So the only remaining problematic case is |
RoslynQuoter doesn't generate the correct code for numeric literals. For example, consider this expression:
Those six values all have different syntax and are also different values. But the code generated by RQ is:
Evaluating this results in:
I think that RQ should generate code that at least preserves semantics. (Ideally, it should preserve the exact syntax used, but I think that's less important.)
The text was updated successfully, but these errors were encountered: