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

Don't treat return as a yield #22299

Closed
wants to merge 1 commit into from
Closed

Don't treat return as a yield #22299

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Mar 2, 2018

Fixes #22298

See in particular the change to generatorTypeCheck14.types. This was working in #3031 but changed in #10676, likely just an oversight as that was a huge baseline change.

Also, changed checkAndAggregateYieldOperandTypes to no longer use pushIfUnique as @sandersn noted that getUnionType can handle duplicates already.

@ghost ghost requested review from sandersn, weswigham and rbuckton March 2, 2018 17:20
@DanielRosenwasser
Copy link
Member

The feature is working as intended. The returned type becomes the value of an IteratorResult when done is true.

@DanielRosenwasser
Copy link
Member

Example:

function* foo() {
  yield 1;
  yield 2;
  return 3;
}

var x = foo();
var r;
do {
  r = x.next()
  console.log(JSON.stringify(r))
} while (!r.done)

// {"value":1,"done":false}
// {"value":2,"done":false}
// {"value":3,"done":true}

@ghost ghost closed this Mar 2, 2018
@ghost ghost deleted the returnInGenerator branch March 2, 2018 23:45
@mhegazy
Copy link
Contributor

mhegazy commented Mar 3, 2018

The feature is working as intended. The returned type becomes the value of an IteratorResult when done is true.

we are currentlly not doing so...

for example yield undefined causes the function to return undefined.

@ghost
Copy link
Author

ghost commented Mar 3, 2018

@mhegazy you are probably confusing this with #22297? This is a different issue I happened to discover while doing that one.

@microsoft microsoft locked and limited conversation to collaborators Jul 3, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants