Skip to content

Incorrect codegen with __TS__UsingAsync #1730

Description

@TooManyLimits
class Thing implements Disposable {
    x: number = 5;
    constructor() {}
    [Symbol.dispose]() {}
}

(async () => {
    using thing = new Thing();
    thing.x = 10;
})();

generates the lua code:

(function()
    return __TS__AsyncAwaiter(function(____awaiter_resolve)
        return ____awaiter_resolve(
            nil,
            __TS__Await(__TS__UsingAsync(
                nil,
                function(thing)
                    return __TS__AsyncAwaiter(function(____awaiter_resolve)
                        thing.x = 10
                    end)
                end,
                __TS__New(Thing)
            ))
        )
    end)
end)(nil)

However, in the definition of __TS__UsingAsync, cb is called with nil as the first parameter. This causes an error at runtime, since thing is nil.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions