Repository navigation
Catchable RangeError; accessors that throw in try are caught; override result types; getter-only abstract field - #731
Merged
Conversation
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
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A check that TypeScript answers with a
RangeErrornow throws aRangeErrorthat acatchcan take. Before, these checks stopped the program the same way a failing assert does. The checks are:/and%by0n("Division by zero");**("Exponent must be non-negative");length =ornew 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:
mlirGenRangeCheckgenerates a__range_check(holds, message)once per module, from TypeScript source, and calls it at each check.--no-default-lib, so noRangeErrorclass), the checks still assert, as before. Thebigint-rangeandarray-lengthctest cases cover that path.Known limitation: an uncaught
RangeErrorprints only "uncaught exception". The old assert printed the message as well.Tests:
range_error_caught.tsis in Error fields are public in core.d.ts; test for a caught RangeError TypeScriptCompilerDefaultLib#57. That PR also makesError's fields public incore.d.ts, soe.messagecompiles. It passes in gc, rc, none and own.Also in this PR (accessor fixes)
tryare caught. A get or set that threw insidetryreached the caller uncaught. Lowering atryrecorded only the calls and throws already in its body, and an accessor op becomes its call after that.trynow records accessor ops as well, and the calls they lower to unwind to the same handler (TsPattern::createCall).tryhandlers.f() { return 3; }overridingf(): numberinferss32, 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.abstract name: T, as TypeScript allows. Before, this was an error about a missingset_name. The setter slot now gets a setter that throws aTypeError, 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.tsand00class_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