Skip to content

An integer literal that does not fit s32 is s64, not u32 - #603

Merged
ASDAlexander77 merged 1 commit into
mainfrom
int-literal-above-s32
Oct 17, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
int-literal-above-s32

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Problem

getIntTypeAttribute typed an integer literal that needs exactly 32 bits ([2^31, 2^32): 3000000000, 2147483648, 0xFFFFFFFF) as ui32. Arithmetic with other integer literals then happened in 32 bits: 1 + 3000000000 printed -1294967295.

Fix

Drop the case 32 that picked unsigned 32; such a literal now takes the default branch and becomes si64, as 5000000000 already did. Literals that fit s32 stay si32.

Tests

  • New 00int_literal_above_s32.ts (compile + jit + rc/none corpus): 1 + 3000000000, * 2, +=, 0xFFFFFFFF + 1, -2147483649, and narrowing into declared s32/u32. Fails on the old compiler with the -1294967295 result.
  • 02numbers.ts wrote INT32_MIN as 0x80000000 >> 0, which relied on the literal being 32-bit; it now writes -2147483648.
  • Release ctest: 0 failures out of 4174.

Behaviour change to note

Bitwise/shift ops on literals in [2^31, 2^32) now compute in 64 bits: 0xFFFFFFFF | 0 is 4294967295 (JS: -1), 0x80000000 >> 0 is 2147483648 (JS: -2147483648). >>> 0 is unchanged. DefaultLib only has -2147483648 in tests/math.ts, whose value is unchanged.

🤖 Generated with Claude Code

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>
@ASDAlexander77
ASDAlexander77 merged commit fdbdd5c into main Oct 17, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the int-literal-above-s32 branch October 17, 2026 23:55
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