Skip to content

Throw and catch booleans and bigints; fix four bigint gaps and <boolean> unboxing - #348

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-throw-bool-bigint
Sep 23, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-throw-bool-bigint

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

throw true and throw 5n were rejected at compile time with "Not supported type in throw".

Throw / catch

  • boolean is thrown as a C++ bool: _N on Windows, _ZTIb on Linux.
  • bigint, which is an i64, is thrown as an __int64: _J on Windows, _ZTIx on Linux.
  • Each gets the same boxing entry that other primitives have for an untyped catch: the Windows copy thunk, and on Linux the catch-all dispatch from Bind an untyped/any catch's value as a real any; catch (e: number) takes an int #347.
  • A bigint literal is a plain i64, so 64-bit integers map to the bigint entries too.
  • Typed catches (catch (e: boolean), catch (e: bigint)) and untyped catches both work. A catch that doesn't match passes the exception on to the next one.

Bigint gaps found along the way (all reachable without exceptions)

  • Boxing a bigint into any crashed the compiler. typeOfAsString had no name for bigint, so BoxOp got a null type tag.
  • Unboxing a bigint from a string failed to compile. ParseIntOp always used atoi/strtol, which return 32 bits. It now uses atoll/strtoll when the result is 64 bits. Plain strtol is also 32 bits on Windows.
  • print(x) of a bigint crashed. The conversion to string was a bare inttoptr, so puts received the value as an address.
  • Comparing two bigints always gave false, even u == v for equal values. LogicOp had no case for bigint and fell through to its "not applicable" constant. Comparing against a literal happened to work, because the literal carries its own integer type.

Also

  • <boolean> of an any failed to compile. createFConstantOf(32, …) built an f64 zero when NUMBER_F64 is set. The f32 branch of the generated ___unbox<boolean> then compared an f32 against that f64.

New test: 00throw_bool_bigint.ts, registered for compile, jit and the rc/none corpus.

Verified locally

  • Windows ctest: 2812/2812.
  • Linux (WSL) ctest: 2806/2806.
  • check-x86-eh.sh: 53/53.
  • The new test also runs as an i686 program under -mm=none and -mm=gc.

🤖 Generated with Claude Code

…an> unboxing

`throw true` and `throw 5n` were rejected ("Not supported type in throw"). A
boolean is now thrown as a C++ bool (`_N` / `_ZTIb`) and a bigint, an i64, as an
__int64 (`_J` / `_ZTIx`), each with the boxing entry the other primitives have
for an untyped catch (Windows copy thunk / Linux catch-all dispatch). A bigint
literal is a plain i64, so 64-bit integers map to the bigint entries too.

Bigint gaps found on the way, each reachable without exceptions:
- boxing a bigint into an `any` crashed the compiler: typeof had no name for it,
  so BoxOp got a null type tag;
- unboxing one from a string failed to compile: ParseIntOp always used atoi/
  strtol (32 bits), now atoll/strtoll for a 64-bit result;
- converting one to a string was a bare inttoptr, so print() of a bigint crashed;
- comparing two bigints was constant false (LogicOp had no case for them).

Also: `<boolean>` of an `any` failed to compile - createFConstantOf(32) built an
f64 zero, which the f32 branch of ___unbox<boolean> compared an f32 against.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 7ada925 into main Sep 23, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-throw-bool-bigint branch September 23, 2026 13:33
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