Skip to content

Keep the grouping of a right operand of + and * in Jass - #1487

Merged
Frotty merged 2 commits into
masterfrom
fix-jass-printer-keeps-grouping
Oct 17, 2026
Merged

Frotty merged 2 commits into
masterfrom
fix-jass-printer-keeps-grouping

Conversation

@Frotty

@Frotty Frotty commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

The Jass printer (ExprPrinter) dropped the parentheses of an equal-precedence right operand for + and * as if they were associative, so a + (b + c) was printed as a + b + c, which Jass reads as (a + b) + c. On reals, 32 bit floats in the game, that can be a different value: -1e8 + 1 is not representable, so 1e8 + (-1e8 + 1) loses the 1 that (1e8 + -1e8) + 1 keeps. Integer and string + are associative, but the printer has no types, so + and * now keep their parentheses like - and /; and and or still lose them. The Lua printer already kept them (LuaTranslationTests.rightOperandsKeepTheirParentheses).

The interpreters run the Jass AST rather than its text, so only the emitted script shows this. Test: ExpressionTests.jassKeepsTheGroupingOfARealSumAndProduct, red before the change. ExpressionTests, OptimizerTests, BugTests, ClassesTests and NewFeatureTests green locally (Windows).

Measured on the 3.0.0 client (Jass, -inline -localOptimizations, operands computed at run time): with a = b = 2^-100 and c = 2^100, (a * (b * c)) * c gives 1 with this change and 0 before it, where the printed a * b * c * c underflows on a * b. The left-grouped control gives 0 in both builds. A sum, 2^24 + (1 + 1), did not discriminate: the game gave 0 for the difference to 2^24 in both groupings and both builds.

The Jass printer dropped the parentheses of `a + (b + c)` and
`a * (b * c)` as if the operators were associative. Jass reads the text
as `(a + b) + c`, and on reals, which are 32 bit floats in the game,
that is a different value. Only and and or still lose them.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T16:45:47.632196Z b0d360b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit 2d4f61d into master Oct 17, 2026
2 checks passed
@Frotty
Frotty deleted the fix-jass-printer-keeps-grouping branch November 25, 2026 08:54
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.

1 participant