Skip to content

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

Closed
Kingwl wants to merge 1 commit into
microsoft:masterfrom
Kingwl:generator-yield-and-return-check
Closed

warn when generator function without any yield expression (#13847)#19413
Kingwl wants to merge 1 commit into
microsoft:masterfrom
Kingwl:generator-yield-and-return-check

Conversation

@Kingwl

@Kingwl Kingwl commented Oct 23, 2017

Copy link
Copy Markdown
Contributor

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
Comment thread src/compiler/checker.ts Outdated

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

Copy link
Copy Markdown
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.

Comment thread src/compiler/diagnosticMessages.json Outdated
"category": "Error",
"code": 1329
},
"generator with 'return statement' must not have zero 'yield return' statements.": {

Copy link
Copy Markdown
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

mhegazy commented Oct 30, 2017

Copy link
Copy Markdown
Contributor

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