Parenthesise a number literal used as a call receiver [patch] - #142
Merged
Merged
Conversation
A signed literal receiver lost its grouping: -2.5.abs() is -(2.5.abs()) in every target, so the call ran and returned the wrong value. An integer receiver ran the dot into the literal, and 5.toString() does not parse in JavaScript or Python. GenerateCallExpression now wraps any number literal receiver in parentheses. Fixes #100 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HsaGezbczZSL9fXfQafs7x
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #100
What was wrong
GenerateCallExpressionwrote the receiver straight in front of.. That caused two problems:-2.5.abs()parses as-(2.5.abs())in every target, so the call returned -2.5 with no error.5.toString()doesn't parse in JavaScript or Python, because the dot is read as a decimal point.Change
LanguageGeneratorBase.GenerateCallExpressionnow wraps every number-literal receiver in parentheses: int, long, float, double andAstLeafNode<int>, of either sign. This makes the output(-2.5).abs()and(5).toString(). Every generator except C uses this path. C passes the receiver as the first argument, so it isn't affected.value.abs()).Tests
CallReceiverLiteralTestscovers three cases:-2.5d.abs(), and the JS/Python output isn't(5).toString().🤖 Generated with Claude Code
https://claude.ai/code/session_01HsaGezbczZSL9fXfQafs7x
Generated by Claude Code