Incorrect codegen with __TS__UsingAsync · Issue #1730 · TypeScriptToLua/TypeScriptToLua · GitHub
Skip to content

Incorrect codegen with __TS__UsingAsync #1730

Open

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.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions