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

warn when generator function without any yield expression (#13847) #19413

Closed

Conversation

Kingwl
Copy link
Contributor

@Kingwl Kingwl commented Oct 23, 2017

Fixes #13847

@Kingwl Kingwl force-pushed the generator-yield-and-return-check branch 2 times, most recently from 5a8a59c to a024434 Compare October 27, 2017 06:15
@@ -18714,6 +18714,18 @@ namespace ts {
}
}

function checkGeneratorWithReturnStatementMustHaveYield (func: FunctionLikeDeclaration) {
let hasReturnStmt = false;
forEachReturnStatement(<Block>func.body, _ => hasReturnStmt = true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems weird that we have to do this walk again. we have already walked the yield statements to get the types a bit earlier. we can just report the error there instead.

@@ -911,6 +911,10 @@
"category": "Error",
"code": 1329
},
"generator with 'return statement' must not have zero 'yield return' statements.": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A generator cannot have a return statement and no yield statements.

@mhegazy
Copy link
Contributor

mhegazy commented Oct 30, 2017

In light of the recent discussion about warnings vs. errors, i want to revisit our decision to accept this proposal in the first place.

@Kingwl Kingwl force-pushed the generator-yield-and-return-check branch from a024434 to e4576ed Compare October 31, 2017 04:15
@Kingwl Kingwl closed this Oct 31, 2017
@Kingwl Kingwl deleted the generator-yield-and-return-check branch October 31, 2017 07:46
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
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