Repository navigation
A number literal above int32 given to a bitwise operator is ToInt32'd; no "redeclared" warning of nested for...of (TSLANG 234) - #1128
Merged
Conversation
…; 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aconstof one, kept 64 bits:0x9e3779b9 ^ 5gave 2654435772 (node: -1640531524),big | 0didn't wrap, and~0x80000000was 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). Au64/s64variable keeps its 64-bit bitwise math and the literal goes to its type, so00int64_shift_bitwise.tsis unchanged (m & 0xFF00000000,0xFF00000000 & m,s64 << 40stay 64-bit).let s = 0x6d2b79f5; s + 0x6d2b79f5wrapping at 32 bits stays: it follows the s32 literal rule (let s: numbergives 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 aconstof such a literal is ToInt32'd first."variable .a redeclared". Two nested
for...ofover the same array both declare.aas that array's variable, the same value, anddeclare()warned. It no longer warns when the name is given the very same value.Tests:
00tslang_issue_234.tsunder gc/rc/none/own (jit + compile), all values checked against node (u64 cases against BigInt), plus a compile withFAIL_REGULAR_EXPRESSION "warning:..."for the nested loop. Full ctest: 10458/10458 passed (Windows, Release).🤖 Generated with Claude Code