Repository navigation
An integer literal that does not fit s32 is s64, not u32 - #603
Merged
Merged
Conversation
getIntTypeAttribute typed a literal with exactly 32 active bits ([2^31, 2^32): 3000000000, 2147483648, 0xFFFFFFFF) as ui32, so arithmetic with other integer literals was done in 32 bits: `1 + 3000000000` printed -1294967295. Such a literal now takes the default branch and becomes si64, like 5000000000 already was; literals that fit s32 stay s32. 02numbers.ts spelled INT32_MIN as `0x80000000 >> 0`, which relied on the literal being 32-bit; it now writes -2147483648. 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.
Problem
getIntTypeAttributetyped an integer literal that needs exactly 32 bits ([2^31, 2^32):3000000000,2147483648,0xFFFFFFFF) asui32. Arithmetic with other integer literals then happened in 32 bits:1 + 3000000000printed-1294967295.Fix
Drop the
case 32that picked unsigned 32; such a literal now takes the default branch and becomessi64, as5000000000already did. Literals that fit s32 staysi32.Tests
00int_literal_above_s32.ts(compile + jit + rc/none corpus):1 + 3000000000,* 2,+=,0xFFFFFFFF + 1,-2147483649, and narrowing into declareds32/u32. Fails on the old compiler with the-1294967295result.02numbers.tswrote INT32_MIN as0x80000000 >> 0, which relied on the literal being 32-bit; it now writes-2147483648.Behaviour change to note
Bitwise/shift ops on literals in [2^31, 2^32) now compute in 64 bits:
0xFFFFFFFF | 0is4294967295(JS:-1),0x80000000 >> 0is2147483648(JS:-2147483648).>>> 0is unchanged. DefaultLib only has-2147483648intests/math.ts, whose value is unchanged.🤖 Generated with Claude Code