Skip to content

Parenthesise a number literal used as a call receiver [patch] - #142

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/call-receiver-parens-100
Sep 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/call-receiver-parens-100

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #100

What was wrong

GenerateCallExpression wrote the receiver straight in front of .. That caused two problems:

  • Signed literal: -2.5.abs() parses as -(2.5.abs()) in every target, so the call returned -2.5 with no error.
  • Integer literal: 5.toString() doesn't parse in JavaScript or Python, because the dot is read as a decimal point.

Change

  • LanguageGeneratorBase.GenerateCallExpression now wraps every number-literal receiver in parentheses: int, long, float, double and AstLeafNode<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.
  • Name receivers are still written bare (value.abs()).

Tests

  • New CallReceiverLiteralTests covers three cases:
    • a negative literal receiver, across the six dot-call generators
    • an integer receiver in JavaScript and Python
    • a name receiver that stays bare
  • With the generator change reverted, the two literal tests fail: C# writes -2.5d.abs(), and the JS/Python output isn't (5).toString().
  • Full suite: 990 passed, 0 failed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HsaGezbczZSL9fXfQafs7x


Generated by Claude Code

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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 4bb5c80 into main Sep 30, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/call-receiver-parens-100 branch September 30, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A negative or integer literal used as a call receiver is not parenthesised: -2.5.abs() negates the result, and 5.toString() is a syntax error

2 participants