Skip to content

Generator vs array used in a ternary generates invalid code #1426

@DoctorGester

Description

@DoctorGester

https://typescripttolua.github.io/play/#code/GYVwdgxgLglg9mAVAAigCxmA5gZwBQCUyA3gFDIXICeMApgDYAmyARAIYsDc5lNDzLAEYtSAX1KlgcAE7I8EBDijIAHsjjBkAbQB0evFGkhayAPyoM2fEQBc2gLoFHJHhQAO0zFDwqCYoA

function* things() {
    yield "a";
    yield "b"
}

for (const x of [...(true ? things() : [])]) {
    print(x)
}

This code incorrectly compiles down to a table.unpack instead of a lua-lib spread function, producing invalid results.
Expected output: print("a"); print("b");
Actual result: nothing

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions