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

Unified Diff: pkg/analyzer/lib/src/generated/parser.dart

Issue 2955063004: Fix recovery to prevent generating a parameter with no name and no type (issue 30020) (Closed)
Patch Set: Created 3 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 | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 765b4c6d7b853e51229af6eaa2082933e44d9050..158d093368ca1b8225c2a49359dbd30a98229af3 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -180,6 +180,12 @@ class Parser {
static const int _MAX_TREE_DEPTH = 300;
/**
+ * A flag indicating whether the analyzer [Parser] factory method
+ * will return a fasta based parser or an analyzer based parser.
+ */
+ static bool useFasta = const bool.fromEnvironment("useFastaParser");
+
+ /**
* The source being parsed.
*/
final Source _source;
@@ -270,12 +276,6 @@ class Parser {
bool parseGenericMethodComments = false;
/**
- * A flag indicating whether the analyzer [Parser] factory method
- * will return a fasta based parser or an analyzer based parser.
- */
- static bool useFasta = const bool.fromEnvironment("useFastaParser");
-
- /**
* Initialize a newly created parser to parse tokens in the given [_source]
* and to report any errors that are found to the given [_errorListener].
*/
@@ -2888,6 +2888,21 @@ class Parser {
} else if (inFunctionType && _matchesIdentifier()) {
type = parseTypeAnnotation(false);
} else if (!optional) {
+ // If there is a valid type immediately following an unexpected token,
+ // then report and skip the unexpected token.
+ Token next = _peek();
+ Keyword nextKeyword = next.keyword;
+ if (nextKeyword == Keyword.FINAL ||
+ nextKeyword == Keyword.CONST ||
+ nextKeyword == Keyword.VAR ||
+ _isTypedIdentifier(next) ||
+ inFunctionType && _tokenMatchesIdentifier(next)) {
+ _reportErrorForCurrentToken(
+ ParserErrorCode.UNEXPECTED_TOKEN, [_currentToken.lexeme]);
+ _advance();
+ return parseFinalConstVarOrType(optional,
+ inFunctionType: inFunctionType);
+ }
_reportErrorForCurrentToken(
ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE);
} else {
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/parser_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698