Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async code generator does not correctly handle labelled blocks #50332

Open
Maxdamantus opened this issue Aug 17, 2022 · 1 comment
Open

async code generator does not correctly handle labelled blocks #50332

Maxdamantus opened this issue Aug 17, 2022 · 1 comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@Maxdamantus
Copy link

Bug Report

When using the "ES5" target, async/await code generation does not correctly handle breaking from labelled blocks.

🔎 Search Terms

break block label async

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about everything

⏯ Playground Link

Playground link with relevant code

💻 Code

Compiler options: --lib ES2015,dom --target ES5

async function foo() {
    tmp: {
        for (let x = 0; x < 4; x++)
            if (await Promise.resolve(true))
                break tmp;
        console.log("Impossible");
        throw 0;
    }
    console.log("Success");
}

foo();

🙁 Actual behavior

"Impossible" is logged, because the break statement seems to short-circuit the inner loop

🙂 Expected behavior

"Success" is logged, because the break statement should short-circuit the outer block

Interestingly, it does seem to handle breaking from outer loops (eg adding a superfluous loop, tmp: for (let nvm = 0; nvm < 1; nvm++) ...), but not plain blocks.

@Maxdamantus
Copy link
Author

I should probably have actually simplified it a bit further, since it's not dependent on any await-based condition:

async function foo() {
    tmp: {
        for (let x = 0; x < 4; x++) {
            break tmp;
            await Promise.resolve();
        }
        console.log("Impossible");
        throw 0;
    }
    console.log("Success");
}
foo();

The code above should be statically known to log Success, since the await never actually happens. The generated code instead jumps to the Impossible branch.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Aug 17, 2022
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Aug 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

2 participants