Skip to content

Catchable RangeError; accessors that throw in try are caught; override result types; getter-only abstract field - #731

Merged
ASDAlexander77 merged 2 commits into
mainfrom
range-error-catchable
Oct 29, 2026
Merged

ASDAlexander77 merged 2 commits into
mainfrom
range-error-catchable

Conversation

@ASDAlexander77

@ASDAlexander77 ASDAlexander77 commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

A check that TypeScript answers with a RangeError now throws a RangeError that a catch can take. Before, these checks stopped the program the same way a failing assert does. The checks are:

  • bigint / and % by 0n ("Division by zero");
  • a negative bigint ** ("Exponent must be non-negative");
  • an invalid array length from length = or new Array(n) ("Invalid array length"). A number must be a whole number in 0..2^32-1. A signed integer must be >= 0. An integer wider than 32 bits must be <= 2^32-1.

How it works:

  • mlirGenRangeCheck generates a __range_check(holds, message) once per module, from TypeScript source, and calls it at each check.
  • Without the default library (--no-default-lib, so no RangeError class), the checks still assert, as before. The bigint-range and array-length ctest cases cover that path.

Known limitation: an uncaught RangeError prints only "uncaught exception". The old assert printed the message as well.

Tests:

Also in this PR (accessor fixes)

  • Accessors that throw inside try are caught. A get or set that threw inside try reached the caller uncaught. Lowering a try recorded only the calls and throws already in its body, and an accessor op becomes its call after that. try now records accessor ops as well, and the calls they lower to unwind to the same handler (TsPattern::createCall).
    • Still open: an accessor reached through an interface field. That call is made by the tagged cell's load or store during the final lowering to LLVM, which has no record of the try handlers.
  • Overrides keep the base's number result. f() { return 3; } overriding f(): number infers s32, but its vtable slot is called as the base's method, so a call through the base read 0. This applied to methods, getters and abstract fields. A method with no return type of its own now takes the numeric return type of the method it overrides.
  • A getter alone may implement abstract name: T, as TypeScript allows. Before, this was an error about a missing set_name. The setter slot now gets a setter that throws a TypeError, as a JavaScript write to a getter-only property does. Without the default library it stops the program with an assert instead.

New ctest tests: 00try_catch_accessor.ts, 00class_override_inferred_return.ts and 00class_accessor_getter_only_abstract.ts. The full ctest suite passes. DefaultLib: gc 180/180, rc and none 179 + 1 skipped, own 169 + 11 skipped.

🤖 Generated with Claude Code

ASDAlexander77 and others added 2 commits October 29, 2026 09:41
A bigint / or % by 0n, a negative bigint **, and an invalid array length
(`length =` and `new Array(n)`, a number or an integer) now call a generated
`__range_check` that throws `new RangeError(message)`, so a `catch` takes it.
Without the default library (`--no-default-lib`, no RangeError class) the
checks still stop the program with an assert, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ber result; a getter alone implements an abstract field

- A get or set inside `try` that throws was never caught: the accessor op is
  lowered to its call after the `try`, which recorded only the calls and throws
  already in its body. Accessor ops are recorded too, and the calls they lower
  to unwind to the same handler.
- A method or getter overriding one that returns a number, with no return type
  of its own (`f() { return 3; }`, s32), now returns the base's type. Its
  vtable slot is called as the base's, so a call through the base read 0.
- A getter alone may implement `abstract name: T`, as TypeScript allows. The
  setter slot gets a setter that throws a TypeError (a failing assert without
  the default library). Before, this was an error naming a missing 'set_name'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77 ASDAlexander77 changed the title RangeError checks throw a catchable RangeError with the default library Catchable RangeError; accessors that throw in try are caught; override result types; getter-only abstract field Oct 29, 2026
@ASDAlexander77
ASDAlexander77 merged commit 083efc4 into main Oct 29, 2026
2 checks passed
@ASDAlexander77
ASDAlexander77 deleted the range-error-catchable branch October 29, 2026 10:39
ASDAlexander77 added a commit that referenced this pull request Oct 29, 2026
A JIT run that ended in an uncaught exception printed only "uncaught
exception". Since the range checks throw a RangeError (#731), that lost the
message their asserts printed. The JIT's exception filter now reads the thrown
value while it is still alive, from the record of the throw: a string, a
number, a boolean or a bigint by its value, a class by its name, and an Error
(core.ts) by its name and message:

    tslang: error: uncaught exception: RangeError: Division by zero

Every read is guarded; a record of another shape is left undescribed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77 added a commit that referenced this pull request Oct 29, 2026
…ped catch, uncaught descriptions; ++/-- on accessors (#732)

* Interface-field accessors that throw in try are caught; a call in a catch can throw to a typed catch

- A load or a store through an interface's field whose slot names a cell of
  accessors calls the getter or setter only once it is lowered to LLVM, after
  the `try`. Such an access inside a `try` now ends its block with a
  ts.AccessorUnwindEdge to the handler (added once the function is one CFG),
  which keeps the landing block and lowers to a branch. The getter or setter
  is called by an invoke unwinding there.
- On Windows a print of several values was a variable-size alloca. In a
  function with exception funclets it moved the stack, and an exception thrown
  by a call in a catch, taken by a typed catch of the same function, had its
  catch object written at the wrong address: a crash, or a stack overflow.
  There the line is now built on the heap and freed once written; so is it in
  a presplit coroutine, where the heap copy leaked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* ++ and -- on a get/set property call the setter

`o.prop++` was an error ("'++'/'--' on a get/set accessor property is not
supported"): there is no reference to store the new value to. MLIRGen now
calls the setter with the getter's value plus or minus one, as `+= 1` does,
and gives the new value for a prefix operator and the old one for a postfix.
This covers instance, static, virtual, `this.`, interface and object-literal
accessors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* An uncaught exception says what was thrown

A JIT run that ended in an uncaught exception printed only "uncaught
exception". Since the range checks throw a RangeError (#731), that lost the
message their asserts printed. The JIT's exception filter now reads the thrown
value while it is still alive, from the record of the throw: a string, a
number, a boolean or a bigint by its value, a class by its name, and an Error
(core.ts) by its name and message:

    tslang: error: uncaught exception: RangeError: Division by zero

Every read is guarded; a record of another shape is left undescribed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ASDAlexander77 added a commit that referenced this pull request Oct 30, 2026
…ge_check is private to each module (#747)

Two failures only a debug build sees, found building the debug default library as the release
workflow does (`--di --opt_level=0`, TSLANG_DEBUG_CRT=/MT) and running its tests:

- `a.every((v) => v < 40)` - since array callbacks take the element's index too, any one-parameter
  callback - was rejected by LLVM in every model: "inlinable function call in a function with a
  DISubprogram location must have a debug location". fewerParametersThunk (#733) made the thunk with
  no location; with --di the debug-info pass gave it a subprogram and its call had none. It now gets a
  subprogram at the place that first needs it and its body is scoped under it, as the catch copy
  thunk (mlirGenCatchCopyThunk) does.
- A program linked against the debug default library failed with "LNK2005: ___range_check already
  defined": the RangeError check (#731) is generated from source as a public function in every module
  that checks, the library's included. It is private to each module now (internal linkage, as the
  thunks). An optimized link dropped one copy, which is why release builds linked.

test-compile-debug-info-glue (debug-info-glue.cmake): the fewer-parameter tests emitted with
`--di --opt_level=0` under every model - test-runner in a release build never compiles with --di.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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