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

Unified Diff: runtime/vm/parser.cc

Issue 2341493002: Fix parsing of generic closure formal parameter (Closed)
Patch Set: Created 4 years, 3 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/language.status » ('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 7c5eefc23cf71e9f26f2671a059eb86940ddaf34..883933f5f902e70f985cba880010c4905eb05c9a 100644
--- a/runtime/vm/parser.cc
+++ b/runtime/vm/parser.cc
@@ -2032,15 +2032,19 @@ void Parser::ParseFormalParameter(bool allow_explicit_default_value,
if (!IsIdentifier()) {
ReportError("parameter name or type expected");
}
- // We have not seen a parameter type yet, so we check if the next
- // identifier could represent a type before parsing it.
- Token::Kind follower = LookaheadToken(1);
- // We have an identifier followed by a 'follower' token.
- // We either parse a type or assume that no type is specified.
- if ((follower == Token::kLT) || // Parameterized type.
- (follower == Token::kPERIOD) || // Qualified class name of type.
- Token::IsIdentifier(follower) || // Parameter name following a type.
- (follower == Token::kTHIS)) { // Field parameter following a type.
+
+ // Lookahead to determine whether the next tokens are a return type
+ // followed by a parameter name.
+ bool found_type = false;
+ {
+ TokenPosScope saved_pos(this);
+ if (TryParseReturnType()) {
+ if (IsIdentifier() || (CurrentToken() == Token::kTHIS)) {
+ found_type = true;
+ }
+ }
+ }
+ if (found_type) {
// The types of formal parameters are never ignored, even in unchecked
// mode, because they are part of the function type of closurized
// functions appearing in type tests with typedefs.
« no previous file with comments | « no previous file | tests/language/language.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698