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); |