Skip to content

Unbraced else whose body is a for-of over a generator, inside a loop: operand does not dominate this use #458

Closed

Description

@ASDAlexander77

A for ... of over a generator, written as an unbraced else branch inside a loop, fails to compile in every memory model.

function* gen() {
    yield 1;
    yield 2;
}

function main() {
    for (let i = 0; i < 2; i++) {
        const it = gen();
        if (i == 0) it.next(); else for (const c of it) { print(c); }
    }
    print("done.");
}

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

else_loop.ts:7:33: error: operand #0 does not dominate this use

These work and print 1, 2, done.:

  • the same code with braces, if (i == 0) { it.next(); } else { for (const c of it) { print(c); } };
  • an unbraced else for (const c of xs) over an array;
  • an unbraced else for (let j = 0; ...).

So the failing combination is an unbraced else whose body is a for ... of over a generator, inside a loop.

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