Skip to content

Fix exponentiation precedence for compound exponents - #8550

Merged
cknitt merged 2 commits into
rescript-lang:masterfrom
cknitt:codex/fix-exponentiation-precedence
Aug 15, 2026
Merged

Fix exponentiation precedence for compound exponents#8550
cknitt merged 2 commits into
rescript-lang:masterfrom
cknitt:codex/fix-exponentiation-precedence

Conversation

@cknitt

@cknitt cknitt commented Aug 15, 2026

Copy link
Copy Markdown
Member

Fixes #8549.

Summary

  • Preserve parentheses around multiplication, division, and modulo expressions used as the right operand of exponentiation.
  • Add regression coverage for float multiplication, division, and modulo, plus bigint multiplication.

Root cause

The JavaScript printer assigned exponentiation a right-operand precedence of 12, equal to multiplication, division, and modulo. Because parentheses are only added when the required precedence is greater than the child expression's precedence, expressions such as a ** (b / c) were emitted as a ** b / c, changing their meaning.

Requiring precedence 13 on the right preserves compound exponents while retaining JavaScript's right-associative a ** b ** c output.

Regression history and backport

This regression was introduced by #7153 when float and integer exponentiation switched from Math.pow calls to native JavaScript **.

The change was included in ReScript 12.0.0, so all 12.x releases are affected. This fix should therefore be backported to the maintained 12.x release branch.

Validation

  • make test
  • make test-syntax
  • make checkformat
  • git diff --check

Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the codex/fix-exponentiation-precedence branch from 58a478c to c7942db Compare August 15, 2026 07:33
@cknitt
cknitt marked this pull request as ready for review August 15, 2026 07:39
@codecov

codecov Bot commented Aug 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.84%. Comparing base (65cf698) to head (254cb45).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8550   +/-   ##
=======================================
  Coverage   74.84%   74.84%           
=======================================
  Files         477      477           
  Lines       63331    63331           
=======================================
  Hits        47398    47398           
  Misses      15933    15933           
Files with missing lines Coverage Δ
compiler/core/js_op_util.ml 56.32% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@pkg-pr-new

pkg-pr-new Bot commented Aug 15, 2026

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8550

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8550

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8550

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8550

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8550

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8550

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8550

commit: 254cb45

@cknitt
cknitt force-pushed the codex/fix-exponentiation-precedence branch from c7942db to e94c929 Compare August 15, 2026 07:54
Signed-off-by: Christoph Knittel <ck@cca.io>
@cknitt
cknitt force-pushed the codex/fix-exponentiation-precedence branch from e94c929 to 254cb45 Compare August 15, 2026 08:25
@cknitt
cknitt enabled auto-merge (squash) August 15, 2026 11:19
@cknitt
cknitt merged commit 932ab67 into rescript-lang:master Aug 15, 2026
41 of 42 checks passed
@cknitt
cknitt deleted the codex/fix-exponentiation-precedence branch August 16, 2026 11:00
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.

Rescript erroneosly omits parentheses with float exponentiation

2 participants