Skip to content

Fix enum exponentiation folding at the int64 boundary - #65716

Open
Anders Hejlsberg (ahejlsberg) wants to merge 4 commits into
mainfrom
copilot/fix-negative-value-enum
Open

Anders Hejlsberg (ahejlsberg) wants to merge 4 commits into
mainfrom
copilot/fix-negative-value-enum

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

TypeScript 7 can fold (2 ** 63) ** 3 in an enum to a negative value because the positive base is converted to an out-of-range int64.

  • Fix: Exclude 2 ** 63 from the exact-integer exponentiation path; preserve -2 ** 63 as a valid endpoint.
  • Coverage: Add boundary cases for odd and even exponents, negative bases, and enum JavaScript and declaration emit.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@ahejlsberg Anders Hejlsberg (ahejlsberg) changed the title [WIP] Fix enum folding to correct positive values in TypeScript 7 Fix enum exponentiation folding at the int64 boundary Nov 28, 2026
@ahejlsberg
Anders Hejlsberg (ahejlsberg) marked this pull request as ready for review November 28, 2026 17:29
Copilot AI balanced review requested due to automatic review settings November 28, 2026 17:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the numeric constant-evaluation boundary fix.

No open issues 🎉

What changed in this PR

Fixes #65703 by preventing the compiler’s numeric constant evaluator from converting 2 ** 63 to an out-of-range int64, which caused incorrect negative enum values.

Changes:

  • Makes the exact-integer exponentiation path’s upper bounds exclusive while preserving -2 ** 63 as a valid base.
  • Adds boundary regression tests and baselines covering JavaScript emit, declaration emit, types, and symbols.
File Description
tsc/​testdata/​tests/​cases/​compiler/​enumExponentiationInt64Boundary.ts Adds enum cases for boundary values, odd/even exponents, and a negative base.
tsc/​testdata/​baselines/​reference/​compiler/​enumExponentiationInt64Boundary.types Records expected types for the regression cases.
tsc/​testdata/​baselines/​reference/​compiler/​enumExponentiationInt64Boundary.symbols Records expected enum symbols.
tsc/​testdata/​baselines/​reference/​compiler/​enumExponentiationInt64Boundary.js Records corrected JavaScript and declaration output.
tsc/​internal/​jsnum/​jsnum.go Excludes 2 ** 63 from integer-conversion bounds.
tsc/​internal/​jsnum/​jsnum_test.go Adds exact numeric expectations at and below the boundary.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TS 7 folds (2 ** 63) ** 3 in an enum to a negative value

3 participants