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

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

Issue 2362873002: Add some errors related to nnbd (Closed)
Patch Set: fixed error range 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 | 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 ab91b3d57119e48531b7befa2827ae147bd4bc80..046a0d8cd6b66f9535176f9173fc78631d85c736 100644
--- a/pkg/analyzer/lib/src/generated/parser.dart
+++ b/pkg/analyzer/lib/src/generated/parser.dart
@@ -2750,6 +2750,7 @@ class Parser {
ExtendsClause parseExtendsClause() {
Token keyword = getAndAdvance();
TypeName superclass = parseTypeName(false);
+ _mustNotBeNullable(superclass, ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS);
return new ExtendsClause(keyword, superclass);
}
@@ -3361,10 +3362,11 @@ class Parser {
ImplementsClause parseImplementsClause() {
Token keyword = getAndAdvance();
List<TypeName> interfaces = <TypeName>[];
- interfaces.add(parseTypeName(false));
- while (_optional(TokenType.COMMA)) {
- interfaces.add(parseTypeName(false));
- }
+ do {
+ TypeName typeName = parseTypeName(false);
+ _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS);
+ interfaces.add(typeName);
+ } while (_optional(TokenType.COMMA));
return new ImplementsClause(keyword, interfaces);
}
@@ -4927,6 +4929,10 @@ class Parser {
TypeParameter parseTypeParameter() {
CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
SimpleIdentifier name = parseSimpleIdentifier(isDeclaration: true);
+ if (_matches(TokenType.QUESTION)) {
+ _reportErrorForCurrentToken(ParserErrorCode.NULLABLE_TYPE_PARAMETER);
+ _advance();
+ }
if (_matchesKeyword(Keyword.EXTENDS)) {
Token keyword = getAndAdvance();
TypeName bound = parseTypeName(false);
@@ -5160,10 +5166,12 @@ class Parser {
*/
WithClause parseWithClause() {
Token withKeyword = getAndAdvance();
- List<TypeName> types = <TypeName>[parseTypeName(false)];
- while (_optional(TokenType.COMMA)) {
- types.add(parseTypeName(false));
- }
+ List<TypeName> types = <TypeName>[];
+ do {
+ TypeName typeName = parseTypeName(false);
+ _mustNotBeNullable(typeName, ParserErrorCode.NULLABLE_TYPE_IN_WITH);
+ types.add(typeName);
+ } while (_optional(TokenType.COMMA));
return new WithClause(withKeyword, types);
}
@@ -5954,6 +5962,16 @@ class Parser {
_currentToken.lexeme == identifier;
/**
+ * Report an error with the given [errorCode] if the given [typeName] has been
+ * marked as nullable.
+ */
+ void _mustNotBeNullable(TypeName typeName, ParserErrorCode errorCode) {
+ if (typeName.question != null) {
+ _reportErrorForToken(errorCode, typeName.question);
+ }
+ }
+
+ /**
* If the current token has the given [type], then advance to the next token
* and return `true`. Otherwise, return `false` without advancing. This method
* should not be invoked with an argument value of [TokenType.GT].
@@ -8623,6 +8641,27 @@ class ParserErrorCode extends ErrorCode {
const ParserErrorCode('NORMAL_BEFORE_OPTIONAL_PARAMETERS',
"Normal parameters must occur before optional parameters");
+ static const ParserErrorCode NULLABLE_TYPE_IN_EXTENDS = const ParserErrorCode(
+ 'NULLABLE_TYPE_IN_EXTENDS',
+ "A nullable type cannot be used in an extends clause",
+ "Remove the '?' from the type name");
+
+ static const ParserErrorCode NULLABLE_TYPE_IN_IMPLEMENTS =
+ const ParserErrorCode(
+ 'NULLABLE_TYPE_IN_IMPLEMENTS',
+ "A nullable type cannot be used in an implements clause",
+ "Remove the '?' from the type name");
+
+ static const ParserErrorCode NULLABLE_TYPE_IN_WITH = const ParserErrorCode(
+ 'NULLABLE_TYPE_IN_WITH',
+ "A nullable type cannot be used in an with clause",
scheglov 2016/09/22 20:30:43 "a with"?
Brian Wilkerson 2016/09/22 20:43:13 Done
+ "Remove the '?' from the type name");
+
+ static const ParserErrorCode NULLABLE_TYPE_PARAMETER = const ParserErrorCode(
+ 'NULLABLE_TYPE_PARAMETER',
+ "Type parameters cannot be nullable",
+ "Remove the '?' from the type name");
+
static const ParserErrorCode POSITIONAL_AFTER_NAMED_ARGUMENT =
const ParserErrorCode('POSITIONAL_AFTER_NAMED_ARGUMENT',
"Positional arguments must occur before named arguments");
« 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