Skip to content

Global T | null | undefined initialised from a T | undefined call: 'ts.Global' op expects region #0 to have 0 or 1 blocks #462

Closed

Description

@ASDAlexander77

A module-level variable of type T | null | undefined, initialised from a call that returns T | undefined, fails to compile in every memory model.

class Node { v = 0; tag = ""; }
function mk(v: number) { const n = new Node(); n.v = v; n.tag = "t" + v; return n; }
function mkU(): Node | undefined { return mk(7); }
let g: Node | null | undefined = mkU();
function main() { print("cls u", g ? g.tag : "none"); }

tslang --emit=jit --no-default-lib -mm=gc (rc the same), main 8b9d631:

error: 'ts.Global' op expects region #0 to have 0 or 1 blocks
let g: Node | null | undefined = mkU();

Expected: cls u t7.

If mkU is declared to return Node | null | undefined instead, the program compiles, with a warning casting from optional (undefined) value, and prints 1. So the problem is converting an optional (T | undefined) to the T | null | undefined union inside a global initializer, which apparently produces control flow that a ts.Global region cannot hold. Found by the review of Shared<T> (own phase 8). Shared<T> | null | undefined fails the same way.

🤖 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