Index: pkg/compiler/lib/src/parser/parser.dart |
diff --git a/pkg/compiler/lib/src/parser/parser.dart b/pkg/compiler/lib/src/parser/parser.dart |
index 988cbf32c63d165be72ac4250dba5fc1b794c509..40389c560798a4345ce916dfb256c462b6abce4e 100644 |
--- a/pkg/compiler/lib/src/parser/parser.dart |
+++ b/pkg/compiler/lib/src/parser/parser.dart |
@@ -426,6 +426,15 @@ class Parser { |
Token parseFormalParameter(Token token, FormalParameterType type) { |
token = parseMetadataStar(token, forParameter: true); |
listener.beginFormalParameter(token); |
+ |
+ // Skip over `covariant` token, if the next token is an identifier or |
+ // modifier. |
+ // This enables the case where `covariant` is the name of the parameter: |
+ // void foo(covariant); |
+ if (identical(token.stringValue, 'covariant') && |
+ token.next.isIdentifier() || isModifier(token.next)) { |
+ token = token.next; |
+ } |
token = parseModifiers(token); |
// TODO(ahe): Validate that there are formal parameters if void. |
token = parseReturnTypeOpt(token); |
@@ -988,9 +997,29 @@ class Parser { |
return null; |
} |
+ /// Removes the optional `covariant` token from the modifiers, if there |
+ /// is no `static` in the list, and `covariant` is the first modifier. |
+ Link<Token> removeOptCovariantTokenIfNotStatic(Link<Token> modifiers) { |
+ if (modifiers.isEmpty || |
+ !identical(modifiers.first.stringValue, 'covariant')) { |
+ return modifiers; |
+ } |
+ for (Token modifier in modifiers.tail) { |
+ if (identical(modifier.stringValue, 'static')) { |
+ return modifiers; |
+ } |
+ } |
+ return modifiers.tail; |
+ } |
+ |
Token parseFields(Token start, Link<Token> modifiers, Token type, |
Token getOrSet, Token name, bool isTopLevel) { |
bool hasType = type != null; |
+ |
+ if (getOrSet == null && !isTopLevel) { |
+ modifiers = removeOptCovariantTokenIfNotStatic(modifiers); |
+ } |
+ |
Token varFinalOrConst = |
expectVarFinalOrConst(modifiers, hasType, !isTopLevel); |
bool isVar = false; |