Skip to content

A value a builtin cannot cast is an error, not a compiler crash (#438) - #496

Merged
ASDAlexander77 merged 1 commit into
mainfrom
fix-array-push-cast
Oct 4, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
fix-array-push-cast

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

h.push(() => 1) into a (() => number)[] crashed the compiler (0xC0000005) with no message. () => 1 is a () => s32, so the cast to the element type fails. push, unshift and splice then passed the cast's null result to the op's builder. Now the cast's own error stops them, the same message an assignment gives:

error: can't assign '() => s32' to '() => number': return type 's32' is not 'number'. ...

The builtins in MLIRCodeLogic.h that used a castFn result without checking it now check it too:

  • push, unshift, splice and view, through one castEach helper;
  • splice's start and delete count;
  • sprintf's buffer size and format, and assert's condition;
  • parseInt, parseFloat and isNaN, which now return ValueOrLogicalResult. parseInt(() => 1) and isNaN(() => 1) crashed on main too.
  • __switchstate's state, and a constant array converted to an array for an array method.

Tests:

  • builtin-cast/*.ts: expect the error for push, unshift, splice, a function pushed into a string[], parseInt and isNaN. Each one crashes on main.
  • 00array_insert_functions.ts: functions whose type matches the element type still go in through push, unshift and splice, and each calls correctly.
Gate Result
Windows full suite (Release) 3816/3816
Linux (WSL) full suite 3801/3801
DefaultLib suite, release + debug, compile + JIT gc 159/159; rc, none 158/159 (weakref_basic is gc-only, as on main)
own corpus no flips (459/617). The new runtime test is an own error by design: one captured n in several escaping closures.

Closes #438

🤖 Generated with Claude Code

`h.push(() => 1)` into `(() => number)[]` crashed the compiler
(0xC0000005) with no message: `() => 1` is `() => s32`, the cast to the
element type fails, and push, unshift and splice handed the null value
it gave to the op's builder. The cast's own error now stops them:
"can't assign '() => s32' to '() => number': return type 's32' is not
'number'", the message an assignment gives.

The builtins in MLIRCodeLogic.h that took a castFn result without
looking at it now check it as well:
- push, unshift, splice and view, through one castEach;
- splice's start and delete count;
- sprintf's buffer size and format, assert's condition;
- parseInt, parseFloat and isNaN, which now return ValueOrLogicalResult
  (parseInt(() => 1) and isNaN(() => 1) crashed too);
- __switchstate's state, and a constant array made into an array for
  an array method.

Closes #438

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit af9596e into main Oct 4, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the fix-array-push-cast branch October 4, 2026 21:20
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.

Array push/unshift/splice crash the compiler when the element cannot be cast (unchecked castFn)

1 participant