Skip to content

Incorrect handling of using keyword with async #1571

@Janrupf

Description

@Janrupf

The using keyword does not work properly when combined with async. Take the following typescript code:

async function getResource(): Promise<AsyncDisposable> {
  return {
    [Symbol.asyncDispose]: async () => {
      console.log("Dispose async!");
    }
  };
}

async function someOtherAsync() {
    // Do async work...
}

async function main() {
  await using resource = await getResource();
  await someOtherAsync();
}

main();

This code compiles and works as expected. However, attempting to compile this with tstl results in the following errors:

Await can only be used inside async functions.(typescript-to-lua)

The error happens at await someOtherAsync(), presumably because the way tstl compiles the using keyword does not account for the function being async in the protected call.

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