Skip to content

Control flow of immediately invoked generator function should not be inlined #23565

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

Closed
ajafff opened this issue Apr 20, 2018 · 0 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@ajafff
Copy link
Contributor

ajafff commented Apr 20, 2018

TypeScript Version: 2.8.1

Search Terms:

Code

// --strict
function test() {
    let v: number;
    (function*() {
        yield 1;
        v = 1;
    })();
    v; // still undefined
}

Expected behavior:
Error Variable 'v' is used before being assigned.

Actual behavior:
No error, but v is still undefined at runtime.

I noticed this while looking through the code in binder.ts where it says that all non-async IIFEs are inlined. Note that adding the async modifier to the generator function brings up the expected error.

Playground Link: https://agentcooper.github.io/typescript-play/#code/GYVwdgxgLglg9mABFApgZygCgJSIN4BQixiANilIgG4BciYIAtgEYoBOA3ESZqJLAgBUOfNxIkAnjBSkAJogCMXceKqIAvIuUkAvthzbiVDogD0pxBhilSicLJTAYYFLII6CQA

Related Issues:

ajafff added a commit to ajafff/TypeScript that referenced this issue Apr 20, 2018
@mhegazy mhegazy added the Bug A bug in TypeScript label Apr 20, 2018
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Apr 20, 2018
@mhegazy mhegazy added this to the TypeScript 2.9 milestone Apr 20, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

2 participants