Index: pkg/analyzer/lib/src/generated/parser.dart |
diff --git a/pkg/analyzer/lib/src/generated/parser.dart b/pkg/analyzer/lib/src/generated/parser.dart |
index ea555a569a305cacc769e3b6a14d38730087a094..64aa175f734e3855fd87a69cb5cf48acd896c4c0 100644 |
--- a/pkg/analyzer/lib/src/generated/parser.dart |
+++ b/pkg/analyzer/lib/src/generated/parser.dart |
@@ -424,6 +424,10 @@ class Parser { |
return true; |
} |
Token afterReturnType = skipTypeName(_currentToken); |
+ if (afterReturnType != null && |
+ _tokenMatchesKeyword(afterReturnType, Keyword.FUNCTION)) { |
+ afterReturnType = skipGenericFunctionTypeAfterReturnType(afterReturnType); |
+ } |
if (afterReturnType == null) { |
// There was no return type, but it is optional, so go back to where we |
// started. |
@@ -538,6 +542,9 @@ class Parser { |
// There was no type name, so this can't be a declaration. |
return false; |
} |
+ if (_tokenMatchesKeyword(token, Keyword.FUNCTION)) { |
+ token = skipGenericFunctionTypeAfterReturnType(token); |
+ } |
if (token.type != TokenType.IDENTIFIER) { |
allowAdditionalTokens = false; |
} |
@@ -1272,28 +1279,25 @@ class Parser { |
_validateModifiersForGetterOrSetterOrMethod(modifiers); |
return _parseMethodDeclarationAfterReturnType(commentAndMetadata, |
modifiers.externalKeyword, modifiers.staticKeyword, returnType); |
- } else { |
- // |
- // We have found an error of some kind. Try to recover. |
- // |
- if (_matchesIdentifier()) { |
- if (_peek().matchesAny(const <TokenType>[ |
+ } else if (_matchesIdentifier() && |
+ _peek().matchesAny(const <TokenType>[ |
TokenType.EQ, |
TokenType.COMMA, |
TokenType.SEMICOLON |
])) { |
- // |
- // We appear to have a variable declaration with a type of "void". |
- // |
- _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
- return parseInitializedIdentifierList( |
- commentAndMetadata, |
- modifiers.staticKeyword, |
- modifiers.covariantKeyword, |
- _validateModifiersForField(modifiers), |
- returnType); |
- } |
+ if (returnType is! GenericFunctionType) { |
+ _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
} |
+ return parseInitializedIdentifierList( |
+ commentAndMetadata, |
+ modifiers.staticKeyword, |
+ modifiers.covariantKeyword, |
+ _validateModifiersForField(modifiers), |
+ returnType); |
+ } else { |
+ // |
+ // We have found an error of some kind. Try to recover. |
+ // |
if (_isOperator(_currentToken)) { |
// |
// We appear to have found an operator declaration without the |
@@ -2078,28 +2082,25 @@ class Parser { |
_validateModifiersForTopLevelFunction(modifiers); |
return parseFunctionDeclaration( |
commentAndMetadata, modifiers.externalKeyword, returnType); |
- } else { |
- // |
- // We have found an error of some kind. Try to recover. |
- // |
- if (_matchesIdentifier()) { |
- if (next.matchesAny(const <TokenType>[ |
+ } else if (_matchesIdentifier() && |
+ next.matchesAny(const <TokenType>[ |
TokenType.EQ, |
TokenType.COMMA, |
TokenType.SEMICOLON |
])) { |
- // |
- // We appear to have a variable declaration with a type of "void". |
- // |
- _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
- return astFactory.topLevelVariableDeclaration( |
- commentAndMetadata.comment, |
- commentAndMetadata.metadata, |
- parseVariableDeclarationListAfterType(null, |
- _validateModifiersForTopLevelVariable(modifiers), null), |
- _expect(TokenType.SEMICOLON)); |
- } |
+ if (returnType is! GenericFunctionType) { |
+ _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
} |
+ return astFactory.topLevelVariableDeclaration( |
+ commentAndMetadata.comment, |
+ commentAndMetadata.metadata, |
+ parseVariableDeclarationListAfterType( |
+ null, _validateModifiersForTopLevelVariable(modifiers), null), |
+ _expect(TokenType.SEMICOLON)); |
+ } else { |
+ // |
+ // We have found an error of some kind. Try to recover. |
+ // |
_reportErrorForToken( |
ParserErrorCode.EXPECTED_EXECUTABLE, _currentToken); |
return null; |
@@ -4138,24 +4139,22 @@ class Parser { |
])) { |
return _parseFunctionDeclarationStatementAfterReturnType( |
commentAndMetadata, returnType); |
- } else { |
- // |
- // We have found an error of some kind. Try to recover. |
- // |
- if (_matchesIdentifier()) { |
- if (next.matchesAny(const <TokenType>[ |
+ } else if (_matchesIdentifier() && |
+ next.matchesAny(const <TokenType>[ |
TokenType.EQ, |
TokenType.COMMA, |
TokenType.SEMICOLON |
])) { |
- // |
- // We appear to have a variable declaration with a type of "void". |
- // |
- _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
- return parseVariableDeclarationStatementAfterMetadata( |
- commentAndMetadata); |
- } |
- } else if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
+ if (returnType is! GenericFunctionType) { |
+ _reportErrorForNode(ParserErrorCode.VOID_VARIABLE, returnType); |
+ } |
+ return _parseVariableDeclarationStatementAfterType( |
+ commentAndMetadata, null, returnType); |
+ } else { |
+ // |
+ // We have found an error of some kind. Try to recover. |
+ // |
+ if (_matches(TokenType.CLOSE_CURLY_BRACKET)) { |
// |
// We appear to have found an incomplete statement at the end of a |
// block. Parse it as a variable declaration. |
@@ -5484,7 +5483,7 @@ class Parser { |
if (!_tokenMatches(startToken, TokenType.OPEN_PAREN)) { |
return null; |
} |
- return (startToken as BeginToken).endToken; |
+ return (startToken as BeginToken).endToken.next; |
} |
/** |
@@ -7597,7 +7596,9 @@ class Parser { |
* variableDeclarationList ';' |
*/ |
VariableDeclarationStatement _parseVariableDeclarationStatementAfterType( |
- CommentAndMetadata commentAndMetadata, Token keyword, TypeName type) { |
+ CommentAndMetadata commentAndMetadata, |
+ Token keyword, |
+ TypeAnnotation type) { |
VariableDeclarationList variableList = |
parseVariableDeclarationListAfterType( |
commentAndMetadata, keyword, type); |