Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(952)

Unified Diff: runtime/vm/parser.cc

Issue 1204103002: Yield in non-generator function is compile-time error (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: yield in non-generator is compile-time error Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/language/async_await_syntax_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/parser.cc
diff --git a/runtime/vm/parser.cc b/runtime/vm/parser.cc
index a8fc76ad3a71ae0f5dbf94083c425e14cffb157e..6cc8e5421676438b17b07fdde16c095f27fbaeca 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -9599,14 +9599,17 @@ AstNode* Parser::ParseYieldStatement() {
bool is_yield_each = false;
const intptr_t yield_pos = TokenPos();
ConsumeToken(); // yield reserved word.
- ASSERT(innermost_function().IsGenerator() ||
- innermost_function().IsSyncGenClosure() ||
- innermost_function().IsAsyncGenerator() ||
- innermost_function().IsAsyncGenClosure());
if (CurrentToken() == Token::kMUL) {
is_yield_each = true;
ConsumeToken();
}
+ if (!innermost_function().IsGenerator() &&
+ !innermost_function().IsGeneratorClosure()) {
+ ReportError(yield_pos,
+ "yield%s statement only allowed in generator functions",
+ is_yield_each ? "*" : "");
+ }
+
AstNode* expr = ParseAwaitableExpr(kAllowConst, kConsumeCascades, NULL);
LetNode* yield = new(Z) LetNode(yield_pos);
« no previous file with comments | « no previous file | tests/language/async_await_syntax_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698