Skip to content

A number literal above int32 given to a bitwise operator is ToInt32'd; no "redeclared" warning of nested for...of (TSLANG 234) - #1128

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-bitwise-int32
Dec 4, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-bitwise-int32

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

TSLANG 234, found porting golden-line's hash32 / mulberry32.

Bitwise ops on big literals. A literal in [2^31, 2^63) is an s64 for its size (#603), and ^ | & << >> on it, or on a const of one, kept 64 bits: 0x9e3779b9 ^ 5 gave 2654435772 (node: -1640531524), big | 0 didn't wrap, and ~0x80000000 was constant-folded to -2147483649 (with a literal type still saying 2147483648).

USER RULING 2026-12-04: literal operands only are JavaScript numbers, ToInt32'd (>>> ToUint32). A u64/s64 variable keeps its 64-bit bitwise math and the literal goes to its type, so 00int64_shift_bitwise.ts is unchanged (m & 0xFF00000000, 0xFF00000000 & m, s64 << 40 stay 64-bit). let s = 0x6d2b79f5; s + 0x6d2b79f5 wrapping at 32 bits stays: it follows the s32 literal rule (let s: number gives JavaScript's sum).

  • MLIRGenImpl.h: isIntegerLiteralValue (an s64 literal constant, read directly or cast to its storage type); the bitwise cast step keeps a 64-bit width only for a non-literal operand (for & | ^ also a right-hand one); ~ constant folding of such a literal gives the s32 ~ToInt32(v).
  • MLIRGenExpressions.cpp: ~ of a const of such a literal is ToInt32'd first.

"variable .a redeclared". Two nested for...of over the same array both declare .a as that array's variable, the same value, and declare() warned. It no longer warns when the name is given the very same value.

Tests: 00tslang_issue_234.ts under gc/rc/none/own (jit + compile), all values checked against node (u64 cases against BigInt), plus a compile with FAIL_REGULAR_EXPRESSION "warning:..." for the nested loop. Full ctest: 10458/10458 passed (Windows, Release).

🤖 Generated with Claude Code

…; no "redeclared" warning of nested for...of (TSLANG 234)

A literal in [2^31, 2^63) is an s64 for its size, and `^ | & << >>` on it (or on a `const` of one) kept 64 bits:
`0x9e3779b9 ^ 5` was 2654435772, `big | 0` did not wrap, `~0x80000000` folded to -2147483649. Ported JavaScript
hashes and PRNGs gave other numbers. USER RULING 2026-12-04: literal operands only are a JavaScript number,
ToInt32'd (`>>>` ToUint32); a u64/s64 variable keeps its 64-bit math, the literal going to its type
(00int64_shift_bitwise.ts unchanged). `s32 + s32` wrapping stays (the s32 literal rule).

Two nested `for (const r of arr) ... for (const o of arr)` warned "variable .a redeclared": both loops' `.a` are
that array's variable, the same value, which is no redeclaration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit e877089 into main Dec 4, 2026
8 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-bitwise-int32 branch December 4, 2026 18:58
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