Skip to content

A throw in a try that declares a class-typed let is not caught (crash in every model) #457

Closed

Description

@ASDAlexander77

A throw inside a try block that declares a class-typed let is not caught: the program crashes instead of running the catch.

class Node { v = 0; }

function tryIt(s: Node) {
    try {
        let t = s;
        print("in try", t.v);
        throw 1;
    } catch {
        print("caught", s.v);
    }
}

function main() {
    const a = new Node();
    tryIt(a);
    print("after", a.v);
}

Expected: in try 0, caught 0, after 0.

Actual, tslang --emit=jit --no-default-lib, main 8b9d631: in try 0, then a crash.

  • gc and none: exception 0x80000003, exit 3. The same happens with the default library.
  • rc: 0xC0000005, exit 139.
  • AOT: 0xC0000409.

These versions of the try body are caught correctly (caught 0, after 0):

  • const t = s; instead of let t = s;;
  • a number local, let n = 5;;
  • no local at all.

let t = new Node(); crashes the same way. So the trigger is a let of a class type declared in the try, followed by a throw.

This is probably the same root cause as #456, where a class-typed let in try has an initializer that throws. Here the initializer succeeds and a later statement throws.

Found by the final review of Shared<T> (own phase 8).

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions