What's wrong
Coder/Languages/LanguageGeneratorBase.cs:559-563: GenerateCallExpression writes GenerateInternal(callExpr.Receiver) followed by . and never wraps the receiver.
PR #92 added the LeadingSign handling (around line 699), but it only covers the unary-minus operand. A signed literal used as a receiver still loses its grouping.
Failure scenario
Signed literal receiver
new CallExpression(Literal.DecimalValue(-2.5), "__abs__") (or "abs") generates -2.5.abs(). C#, C++, Go, Rust, Python and JavaScript all do this, and C# writes -2.5d.abs().
Unary minus binds looser than member access, so this means -(2.5.abs()). In Python, -2.5.__abs__() evaluates to -2.5, while (-2.5).__abs__() gives 2.5. The generated code runs and returns the wrong value, with no error.
Integer literal receiver
new CallExpression(Literal.Number(5), "toString") generates 5.toString(). The output doesn't parse:
- Node:
SyntaxError: Invalid or unexpected token
- Python:
SyntaxError: invalid decimal literal
-5.toString() is also a SyntaxError in Node.
I reproduced these by running the built ktsu.Coder.dll and executing its output with python3 and node.
Suggested fix / acceptance criteria
- In
GenerateCallExpression, parenthesise a receiver that is a literal with a leading sign. The existing LeadingSign helper can do this.
- Also parenthesise a bare integer literal receiver, at least for Python and JavaScript.
- Add generator tests:
(-2.5).abs() for every language
(5).toString() for JavaScript and Python
What's wrong
Coder/Languages/LanguageGeneratorBase.cs:559-563:GenerateCallExpressionwritesGenerateInternal(callExpr.Receiver)followed by.and never wraps the receiver.PR #92 added the
LeadingSignhandling (around line 699), but it only covers the unary-minus operand. A signed literal used as a receiver still loses its grouping.Failure scenario
Signed literal receiver
new CallExpression(Literal.DecimalValue(-2.5), "__abs__")(or"abs") generates-2.5.abs(). C#, C++, Go, Rust, Python and JavaScript all do this, and C# writes-2.5d.abs().Unary minus binds looser than member access, so this means
-(2.5.abs()). In Python,-2.5.__abs__()evaluates to -2.5, while(-2.5).__abs__()gives2.5. The generated code runs and returns the wrong value, with no error.Integer literal receiver
new CallExpression(Literal.Number(5), "toString")generates5.toString(). The output doesn't parse:SyntaxError: Invalid or unexpected tokenSyntaxError: invalid decimal literal-5.toString()is also a SyntaxError in Node.I reproduced these by running the built
ktsu.Coder.dlland executing its output withpython3andnode.Suggested fix / acceptance criteria
GenerateCallExpression, parenthesise a receiver that is a literal with a leading sign. The existingLeadingSignhelper can do this.(-2.5).abs()for every language(5).toString()for JavaScript and Python