Skip to content

A sign-neutral iN is signed: it prints, widens and compares keeping its sign - #432

Merged
ASDAlexander77 merged 1 commit into
mainfrom
signless-int-signed
Oct 1, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
signless-int-signed

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Problem

A sign-neutral integer (i8 … i64) lost its sign:

Code Result before
let a: i32 = -1; print(a) 4294967295, although a converts to number as -1
let b: i8 = -5 prints 251
let c: i64 = -7 holds 4294967289: the s32 literal was zero-extended
let d: i16 = -300; d < 0 false: d was widened with zeros and compared as 65236

A widening cast sign-extended only when both sides were signed integers. Otherwise it fell through to the zero-extension in castLLVMTypesLogic, which sees only the signless LLVM types.

Fix

In CastLogicHelper.h:

  • Widening follows the source: a signed or sign-neutral integer sign-extends, to any wider integer or to index. Only an unsigned one zero-extends. This replaces the two narrower sign-extension cases, signed→signed and signed→index.
  • Printing: a sign-neutral integer prints signed, matching how it already compares and converts to number. uN still prints unsigned.

Tests

  • New 00signless_int_signed.ts, run as compile and jit. It covers i8, i16, i32 and i64 printing and comparing, i32 → index, i32 in any, and that unsigned sources still widen with zeros. It passes under gc, rc and none.
  • Release suite: 3349/3349.
  • DefaultLib rebuilt with this compiler (release gc): 159/159 compiled and 159/159 under JIT.
  • Not run: Debug builds, x86, -mm=own.

🤖 Generated with Claude Code

…ts sign

`let a: i32 = -1` printed 4294967295 (while it converted to number as -1),
`let b: i8 = -5` printed 251, and widening to a larger integer zero-extended unless
both sides were signed: `let c: i64 = -7` held 4294967289, and `i16` -300 compared
with 0 as 65236, so `d < 0` was false.

Widening now follows the source: a signed or sign-neutral integer sign-extends
(to any wider integer or index), only an unsigned one zero-extends. A sign-neutral
integer prints signed; uN still prints unsigned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 0c5bbe9 into main Oct 1, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the signless-int-signed branch October 1, 2026 23:13
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