Index: pkg/analyzer/test/generated/parser_test.dart |
diff --git a/pkg/analyzer/test/generated/parser_test.dart b/pkg/analyzer/test/generated/parser_test.dart |
index d979ed32bf8d1bf713f23bdaf0aaad38d7a4f495..95fa6416fee17895cdc2a08dcadbc7ce8c6b7339 100644 |
--- a/pkg/analyzer/test/generated/parser_test.dart |
+++ b/pkg/analyzer/test/generated/parser_test.dart |
@@ -336,7 +336,21 @@ class ComplexParserTest extends ParserTestCase { |
BinaryExpression, expression.condition); |
} |
- void test_conditionalExpression_precedence_nullableType() { |
+ void test_conditionalExpression_precedence_nullableType_as() { |
+ enableNnbd = true; |
+ Expression expression = parseExpression('x as String ? (x + y) : z'); |
+ expect(expression, isNotNull); |
+ expect(expression, new isInstanceOf<ConditionalExpression>()); |
+ ConditionalExpression conditional = expression; |
+ Expression condition = conditional.condition; |
+ expect(condition, new isInstanceOf<AsExpression>()); |
+ Expression thenExpression = conditional.thenExpression; |
+ expect(thenExpression, new isInstanceOf<ParenthesizedExpression>()); |
+ Expression elseExpression = conditional.elseExpression; |
+ expect(elseExpression, new isInstanceOf<SimpleIdentifier>()); |
+ } |
+ |
+ void test_conditionalExpression_precedence_nullableType_is() { |
enableNnbd = true; |
Expression expression = parseExpression('x is String ? (x + y) : z'); |
expect(expression, isNotNull); |
@@ -573,114 +587,6 @@ void f() { |
*/ |
@reflectiveTest |
class ErrorParserTest extends ParserTestCase { |
- void fail_expectedListOrMapLiteral() { |
- // It isn't clear that this test can ever pass. The parser is currently |
- // create a synthetic list literal in this case, but isSynthetic() isn't |
- // overridden for ListLiteral. The problem is that the synthetic list |
- // literals that are being created are not always zero length (because they |
- // could have type parameters), which violates the contract of |
- // isSynthetic(). |
- createParser('1'); |
- TypedLiteral literal = parser.parseListOrMapLiteral(null); |
- expectNotNullIfNoErrors(literal); |
- listener |
- .assertErrorsWithCodes([ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); |
- expect(literal.isSynthetic, isTrue); |
- } |
- |
- void fail_illegalAssignmentToNonAssignable_superAssigned() { |
- // TODO(brianwilkerson) When this test starts to pass, remove the test |
- // test_illegalAssignmentToNonAssignable_superAssigned. |
- parseExpression( |
- "super = x;", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
- } |
- |
- void fail_invalidCommentReference__new_nonIdentifier() { |
- // This test fails because the method parseCommentReference returns null. |
- createParser(''); |
- CommentReference reference = parser.parseCommentReference('new 42', 0); |
- expectNotNullIfNoErrors(reference); |
- listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
- } |
- |
- void fail_invalidCommentReference__new_tooMuch() { |
- createParser(''); |
- CommentReference reference = parser.parseCommentReference('new a.b.c.d', 0); |
- expectNotNullIfNoErrors(reference); |
- listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
- } |
- |
- void fail_invalidCommentReference__nonNew_nonIdentifier() { |
- // This test fails because the method parseCommentReference returns null. |
- createParser(''); |
- CommentReference reference = parser.parseCommentReference('42', 0); |
- expectNotNullIfNoErrors(reference); |
- listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
- } |
- |
- void fail_invalidCommentReference__nonNew_tooMuch() { |
- createParser(''); |
- CommentReference reference = parser.parseCommentReference('a.b.c.d', 0); |
- expectNotNullIfNoErrors(reference); |
- listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
- } |
- |
- void fail_missingClosingParenthesis() { |
- // It is possible that it is not possible to generate this error (that it's |
- // being reported in code that cannot actually be reached), but that hasn't |
- // been proven yet. |
- createParser('(int a, int b ;'); |
- FormalParameterList list = parser.parseFormalParameterList(); |
- expectNotNullIfNoErrors(list); |
- listener |
- .assertErrorsWithCodes([ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); |
- } |
- |
- void fail_missingFunctionParameters_local_nonVoid_block() { |
- // The parser does not recognize this as a function declaration, so it tries |
- // to parse it as an expression statement. It isn't clear what the best |
- // error message is in this case. |
- ParserTestCase.parseStatement( |
- "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
- } |
- |
- void fail_missingFunctionParameters_local_nonVoid_expression() { |
- // The parser does not recognize this as a function declaration, so it tries |
- // to parse it as an expression statement. It isn't clear what the best |
- // error message is in this case. |
- ParserTestCase.parseStatement( |
- "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
- } |
- |
- void fail_namedFunctionExpression() { |
- createParser('f() {}'); |
- Expression expression = parser.parsePrimaryExpression(); |
- expectNotNullIfNoErrors(expression); |
- listener.assertErrorsWithCodes([ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); |
- expect(expression, new isInstanceOf<FunctionExpression>()); |
- } |
- |
- void fail_unexpectedToken_invalidPostfixExpression() { |
- // Note: this might not be the right error to produce, but some error should |
- // be produced |
- parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); |
- } |
- |
- void fail_varAndType_local() { |
- // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
- // this would be a better error message. |
- ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
- } |
- |
- void fail_varAndType_parameter() { |
- // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
- // this would be a better error message. |
- createParser('(var int x)'); |
- FormalParameterList list = parser.parseFormalParameterList(); |
- expectNotNullIfNoErrors(list); |
- listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); |
- } |
- |
void test_abstractClassMember_constructor() { |
createParser('abstract C.c();'); |
ClassMember member = parser.parseClassMember('C'); |
@@ -1147,6 +1053,22 @@ class Foo { |
[new AnalysisError(null, 2, 1, ParserErrorCode.MISSING_IDENTIFIER)]); |
} |
+ @failingTest |
+ void test_expectedListOrMapLiteral() { |
+ // It isn't clear that this test can ever pass. The parser is currently |
+ // create a synthetic list literal in this case, but isSynthetic() isn't |
+ // overridden for ListLiteral. The problem is that the synthetic list |
+ // literals that are being created are not always zero length (because they |
+ // could have type parameters), which violates the contract of |
+ // isSynthetic(). |
+ createParser('1'); |
+ TypedLiteral literal = parser.parseListOrMapLiteral(null); |
+ expectNotNullIfNoErrors(literal); |
+ listener |
+ .assertErrorsWithCodes([ParserErrorCode.EXPECTED_LIST_OR_MAP_LITERAL]); |
+ expect(literal.isSynthetic, isTrue); |
+ } |
+ |
void test_expectedStringLiteral() { |
createParser('1'); |
StringLiteral literal = parser.parseStringLiteral(); |
@@ -1496,7 +1418,7 @@ class Foo { |
void test_illegalAssignmentToNonAssignable_superAssigned() { |
// TODO(brianwilkerson) When the test |
- // fail_illegalAssignmentToNonAssignable_superAssigned starts to pass, |
+ // test_illegalAssignmentToNonAssignable_superAssigned_failing starts to pass, |
// remove this test (there should only be one error generated, but we're |
// keeping this test until that time so that we can catch other forms of |
// regressions). |
@@ -1506,6 +1428,14 @@ class Foo { |
]); |
} |
+ @failingTest |
+ void test_illegalAssignmentToNonAssignable_superAssigned_failing() { |
+ // TODO(brianwilkerson) When this test starts to pass, remove the test |
+ // test_illegalAssignmentToNonAssignable_superAssigned. |
+ parseExpression( |
+ "super = x;", [ParserErrorCode.ILLEGAL_ASSIGNMENT_TO_NON_ASSIGNABLE]); |
+ } |
+ |
void test_implementsBeforeExtends() { |
ParserTestCase.parseCompilationUnit("class A implements B extends C {}", |
[ParserErrorCode.IMPLEMENTS_BEFORE_EXTENDS]); |
@@ -1544,6 +1474,40 @@ class Foo { |
listener.assertErrorsWithCodes([ParserErrorCode.INVALID_CODE_POINT]); |
} |
+ @failingTest |
+ void test_invalidCommentReference__new_nonIdentifier() { |
+ // This test fails because the method parseCommentReference returns null. |
+ createParser(''); |
+ CommentReference reference = parser.parseCommentReference('new 42', 0); |
+ expectNotNullIfNoErrors(reference); |
+ listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
+ } |
+ |
+ @failingTest |
+ void test_invalidCommentReference__new_tooMuch() { |
+ createParser(''); |
+ CommentReference reference = parser.parseCommentReference('new a.b.c.d', 0); |
+ expectNotNullIfNoErrors(reference); |
+ listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
+ } |
+ |
+ @failingTest |
+ void test_invalidCommentReference__nonNew_nonIdentifier() { |
+ // This test fails because the method parseCommentReference returns null. |
+ createParser(''); |
+ CommentReference reference = parser.parseCommentReference('42', 0); |
+ expectNotNullIfNoErrors(reference); |
+ listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
+ } |
+ |
+ @failingTest |
+ void test_invalidCommentReference__nonNew_tooMuch() { |
+ createParser(''); |
+ CommentReference reference = parser.parseCommentReference('a.b.c.d', 0); |
+ expectNotNullIfNoErrors(reference); |
+ listener.assertErrorsWithCodes([ParserErrorCode.INVALID_COMMENT_REFERENCE]); |
+ } |
+ |
void test_invalidHexEscape_invalidDigit() { |
createParser("'\\x0 a'"); |
StringLiteral literal = parser.parseStringLiteral(); |
@@ -1824,6 +1788,18 @@ class Foo { |
"class A class B {}", [ParserErrorCode.MISSING_CLASS_BODY]); |
} |
+ @failingTest |
+ void test_missingClosingParenthesis() { |
+ // It is possible that it is not possible to generate this error (that it's |
+ // being reported in code that cannot actually be reached), but that hasn't |
+ // been proven yet. |
+ createParser('(int a, int b ;'); |
+ FormalParameterList list = parser.parseFormalParameterList(); |
+ expectNotNullIfNoErrors(list); |
+ listener |
+ .assertErrorsWithCodes([ParserErrorCode.MISSING_CLOSING_PARENTHESIS]); |
+ } |
+ |
void test_missingConstFinalVarOrType_static() { |
ParserTestCase.parseCompilationUnit("class A { static f; }", |
[ParserErrorCode.MISSING_CONST_FINAL_VAR_OR_TYPE]); |
@@ -1877,6 +1853,24 @@ class Foo { |
listener.assertErrorsWithCodes([ParserErrorCode.MISSING_FUNCTION_BODY]); |
} |
+ @failingTest |
+ void test_missingFunctionParameters_local_nonVoid_block() { |
+ // The parser does not recognize this as a function declaration, so it tries |
+ // to parse it as an expression statement. It isn't clear what the best |
+ // error message is in this case. |
+ ParserTestCase.parseStatement( |
+ "int f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
+ } |
+ |
+ @failingTest |
+ void test_missingFunctionParameters_local_nonVoid_expression() { |
+ // The parser does not recognize this as a function declaration, so it tries |
+ // to parse it as an expression statement. It isn't clear what the best |
+ // error message is in this case. |
+ ParserTestCase.parseStatement( |
+ "int f => x;", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
+ } |
+ |
void test_missingFunctionParameters_local_void_block() { |
ParserTestCase.parseStatement( |
"void f { return x;}", [ParserErrorCode.MISSING_FUNCTION_PARAMETERS]); |
@@ -2155,6 +2149,15 @@ class Foo { |
[ParserErrorCode.MULTIPLE_WITH_CLAUSES]); |
} |
+ @failingTest |
+ void test_namedFunctionExpression() { |
+ createParser('f() {}'); |
+ Expression expression = parser.parsePrimaryExpression(); |
+ expectNotNullIfNoErrors(expression); |
+ listener.assertErrorsWithCodes([ParserErrorCode.NAMED_FUNCTION_EXPRESSION]); |
+ expect(expression, new isInstanceOf<FunctionExpression>()); |
+ } |
+ |
void test_namedParameterOutsideGroup() { |
createParser('(a, b : 0)'); |
FormalParameterList list = parser.parseFormalParameterList(); |
@@ -2207,6 +2210,39 @@ class Foo { |
.assertErrorsWithCodes([ParserErrorCode.NON_USER_DEFINABLE_OPERATOR]); |
} |
+ void test_nullableTypeInExtends() { |
+ enableNnbd = true; |
+ createParser('extends B?'); |
+ ExtendsClause clause = parser.parseExtendsClause(); |
+ expectNotNullIfNoErrors(clause); |
+ listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_EXTENDS]); |
+ } |
+ |
+ void test_nullableTypeInImplements() { |
+ enableNnbd = true; |
+ createParser('implements I?'); |
+ ImplementsClause clause = parser.parseImplementsClause(); |
+ expectNotNullIfNoErrors(clause); |
+ listener |
+ .assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_IMPLEMENTS]); |
+ } |
+ |
+ void test_nullableTypeInWith() { |
+ enableNnbd = true; |
+ createParser('with M?'); |
+ WithClause clause = parser.parseWithClause(); |
+ expectNotNullIfNoErrors(clause); |
+ listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_IN_WITH]); |
+ } |
+ |
+ void test_nullableTypeParameter() { |
+ enableNnbd = true; |
+ createParser('T?'); |
+ TypeParameter parameter = parser.parseTypeParameter(); |
+ expectNotNullIfNoErrors(parameter); |
+ listener.assertErrorsWithCodes([ParserErrorCode.NULLABLE_TYPE_PARAMETER]); |
+ } |
+ |
void test_optionalAfterNormalParameters_named() { |
ParserTestCase.parseCompilationUnit( |
"f({a}, b) {}", [ParserErrorCode.NORMAL_BEFORE_OPTIONAL_PARAMETERS]); |
@@ -2498,6 +2534,13 @@ m() { |
"String s = (null));", [ParserErrorCode.UNEXPECTED_TOKEN]); |
} |
+ @failingTest |
+ void test_unexpectedToken_invalidPostfixExpression() { |
+ // Note: this might not be the right error to produce, but some error should |
+ // be produced |
+ parseExpression("f()++", [ParserErrorCode.UNEXPECTED_TOKEN]); |
+ } |
+ |
void test_unexpectedToken_returnInExpressionFuntionBody() { |
ParserTestCase.parseCompilationUnit( |
"f() => return null;", [ParserErrorCode.UNEXPECTED_TOKEN]); |
@@ -2605,6 +2648,23 @@ void main() { |
"class C { var int x; }", [ParserErrorCode.VAR_AND_TYPE]); |
} |
+ @failingTest |
+ void test_varAndType_local() { |
+ // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
+ // this would be a better error message. |
+ ParserTestCase.parseStatement("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
+ } |
+ |
+ @failingTest |
+ void test_varAndType_parameter() { |
+ // This is currently reporting EXPECTED_TOKEN for a missing semicolon, but |
+ // this would be a better error message. |
+ createParser('(var int x)'); |
+ FormalParameterList list = parser.parseFormalParameterList(); |
+ expectNotNullIfNoErrors(list); |
+ listener.assertErrorsWithCodes([ParserErrorCode.VAR_AND_TYPE]); |
+ } |
+ |
void test_varAndType_topLevelVariable() { |
ParserTestCase |
.parseCompilationUnit("var int x;", [ParserErrorCode.VAR_AND_TYPE]); |
@@ -2852,7 +2912,6 @@ class ParserTestCase extends EngineTestCase { |
// |
parser = new Parser(source, listener); |
parser.enableAssertInitializer = enableAssertInitializer; |
- parser.parseAsync = parseAsync; |
parser.parseGenericMethods = enableGenericMethods; |
parser.parseGenericMethodComments = enableGenericMethodComments; |
parser.parseFunctionBodies = parseFunctionBodies; |
@@ -2989,18 +3048,6 @@ class ParserTestCase extends EngineTestCase { |
*/ |
@reflectiveTest |
class RecoveryParserTest extends ParserTestCase { |
- void fail_incomplete_returnType() { |
- ParserTestCase.parseCompilationUnit(r''' |
-Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { |
- if (map == null) return null; |
- Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
- map.forEach((name, value) { |
- result[new Symbol(name)] = value; |
- }); |
- return result; |
-}'''); |
- } |
- |
void test_additiveExpression_missing_LHS() { |
BinaryExpression expression = |
parseExpression("+ y", [ParserErrorCode.MISSING_IDENTIFIER]); |
@@ -3541,6 +3588,19 @@ class B = Object with A {}''', |
[ParserErrorCode.MISSING_ASSIGNMENT_IN_INITIALIZER]); |
} |
+ @failingTest |
+ void test_incomplete_returnType() { |
+ ParserTestCase.parseCompilationUnit(r''' |
+Map<Symbol, convertStringToSymbolMap(Map<String, dynamic> map) { |
+ if (map == null) return null; |
+ Map<Symbol, dynamic> result = new Map<Symbol, dynamic>(); |
+ map.forEach((name, value) { |
+ result[new Symbol(name)] = value; |
+ }); |
+ return result; |
+}'''); |
+ } |
+ |
void test_incomplete_topLevelFunction() { |
ParserTestCase.parseCompilationUnit( |
"foo();", [ParserErrorCode.MISSING_FUNCTION_BODY]); |
@@ -4192,56 +4252,6 @@ class C { |
*/ |
@reflectiveTest |
class SimpleParserTest extends ParserTestCase { |
- void fail_parseAwaitExpression_inSync() { |
- // This test requires better error recovery than we currently have. In |
- // particular, we need to be able to distinguish between an await expression |
- // in the wrong context, and the use of 'await' as an identifier. |
- createParser('m() { return await x + await y; }'); |
- MethodDeclaration method = parser.parseClassMember('C'); |
- expectNotNullIfNoErrors(method); |
- listener.assertNoErrors(); |
- FunctionBody body = method.body; |
- EngineTestCase.assertInstanceOf( |
- (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); |
- Statement statement = (body as BlockFunctionBody).block.statements[0]; |
- EngineTestCase.assertInstanceOf( |
- (obj) => obj is ReturnStatement, ReturnStatement, statement); |
- Expression expression = (statement as ReturnStatement).expression; |
- EngineTestCase.assertInstanceOf( |
- (obj) => obj is BinaryExpression, BinaryExpression, expression); |
- EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, |
- AwaitExpression, (expression as BinaryExpression).leftOperand); |
- EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, |
- AwaitExpression, (expression as BinaryExpression).rightOperand); |
- } |
- |
- void fail_parseCommentReference_this() { |
- // This fails because we are returning null from the method and asserting |
- // that the return value is not null. |
- createParser(''); |
- CommentReference reference = parser.parseCommentReference('this', 5); |
- expectNotNullIfNoErrors(reference); |
- listener.assertNoErrors(); |
- SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( |
- (obj) => obj is SimpleIdentifier, |
- SimpleIdentifier, |
- reference.identifier); |
- expect(identifier.token, isNotNull); |
- expect(identifier.name, "a"); |
- expect(identifier.offset, 5); |
- } |
- |
- void fail_parseStatement_functionDeclaration_noReturnType_typeParameters() { |
- enableGenericMethods = true; |
- createParser('f<E>(a, b) {};'); |
- Statement statement = parser.parseStatement2(); |
- expectNotNullIfNoErrors(statement); |
- listener.assertNoErrors(); |
- expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
- FunctionDeclarationStatement declaration = statement; |
- expect(declaration.functionDeclaration, isNotNull); |
- } |
- |
void test_computeStringValue_emptyInterpolationPrefix() { |
expect(_computeStringValue("'''", true, false), ""); |
} |
@@ -5116,6 +5126,30 @@ class SimpleParserTest extends ParserTestCase { |
statement); |
} |
+ @failingTest |
+ void test_parseAwaitExpression_inSync() { |
+ // This test requires better error recovery than we currently have. In |
+ // particular, we need to be able to distinguish between an await expression |
+ // in the wrong context, and the use of 'await' as an identifier. |
+ createParser('m() { return await x + await y; }'); |
+ MethodDeclaration method = parser.parseClassMember('C'); |
+ expectNotNullIfNoErrors(method); |
+ listener.assertNoErrors(); |
+ FunctionBody body = method.body; |
+ EngineTestCase.assertInstanceOf( |
+ (obj) => obj is BlockFunctionBody, BlockFunctionBody, body); |
+ Statement statement = (body as BlockFunctionBody).block.statements[0]; |
+ EngineTestCase.assertInstanceOf( |
+ (obj) => obj is ReturnStatement, ReturnStatement, statement); |
+ Expression expression = (statement as ReturnStatement).expression; |
+ EngineTestCase.assertInstanceOf( |
+ (obj) => obj is BinaryExpression, BinaryExpression, expression); |
+ EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, |
+ AwaitExpression, (expression as BinaryExpression).leftOperand); |
+ EngineTestCase.assertInstanceOf((obj) => obj is AwaitExpression, |
+ AwaitExpression, (expression as BinaryExpression).rightOperand); |
+ } |
+ |
void test_parseBitwiseAndExpression_normal() { |
createParser('x & y'); |
Expression expression = parser.parseBitwiseAndExpression(); |
@@ -6786,6 +6820,23 @@ void'''); |
expect(nextToken.type, TokenType.EOF); |
} |
+ @failingTest |
+ void test_parseCommentReference_this() { |
+ // This fails because we are returning null from the method and asserting |
+ // that the return value is not null. |
+ createParser(''); |
+ CommentReference reference = parser.parseCommentReference('this', 5); |
+ expectNotNullIfNoErrors(reference); |
+ listener.assertNoErrors(); |
+ SimpleIdentifier identifier = EngineTestCase.assertInstanceOf( |
+ (obj) => obj is SimpleIdentifier, |
+ SimpleIdentifier, |
+ reference.identifier); |
+ expect(identifier.token, isNotNull); |
+ expect(identifier.name, "a"); |
+ expect(identifier.offset, 5); |
+ } |
+ |
void test_parseCommentReferences_multiLine() { |
DocumentationCommentToken token = new DocumentationCommentToken( |
TokenType.MULTI_LINE_COMMENT, "/** xxx [a] yyy [bb] zzz */", 3); |
@@ -10079,6 +10130,27 @@ void'''); |
expect(expression.argumentList, isNotNull); |
} |
+ void test_parseInstanceCreationExpression_type_typeParameters_nullable() { |
+ enableNnbd = true; |
+ Token token = TokenFactory.tokenFromKeyword(Keyword.NEW); |
+ createParser('A<B?>()'); |
+ InstanceCreationExpression expression = |
+ parser.parseInstanceCreationExpression(token); |
+ expectNotNullIfNoErrors(expression); |
+ listener.assertNoErrors(); |
+ expect(expression.keyword, token); |
+ ConstructorName name = expression.constructorName; |
+ expect(name, isNotNull); |
+ TypeName type = name.type; |
+ expect(type, isNotNull); |
+ expect(name.period, isNull); |
+ expect(name.name, isNull); |
+ expect(expression.argumentList, isNotNull); |
+ NodeList<TypeName> arguments = type.typeArguments.arguments; |
+ expect(arguments, hasLength(1)); |
+ expect(arguments[0].question, isNotNull); |
+ } |
+ |
void test_parseLibraryDirective() { |
createParser('library l;'); |
LibraryDirective directive = |
@@ -11526,6 +11598,19 @@ void'''); |
expect(asExpression.type, isNotNull); |
} |
+ void test_parseRelationalExpression_as_nullable() { |
+ enableNnbd = true; |
+ createParser('x as Y?)'); |
+ Expression expression = parser.parseRelationalExpression(); |
+ expectNotNullIfNoErrors(expression); |
+ listener.assertNoErrors(); |
+ expect(expression, new isInstanceOf<AsExpression>()); |
+ AsExpression asExpression = expression; |
+ expect(asExpression.expression, isNotNull); |
+ expect(asExpression.asOperator, isNotNull); |
+ expect(asExpression.type, isNotNull); |
+ } |
+ |
void test_parseRelationalExpression_is() { |
createParser('x is y'); |
Expression expression = parser.parseRelationalExpression(); |
@@ -11539,6 +11624,20 @@ void'''); |
expect(isExpression.type, isNotNull); |
} |
+ void test_parseRelationalExpression_is_nullable() { |
+ enableNnbd = true; |
+ createParser('x is y?)'); |
+ Expression expression = parser.parseRelationalExpression(); |
+ expectNotNullIfNoErrors(expression); |
+ listener.assertNoErrors(); |
+ expect(expression, new isInstanceOf<IsExpression>()); |
+ IsExpression isExpression = expression; |
+ expect(isExpression.expression, isNotNull); |
+ expect(isExpression.isOperator, isNotNull); |
+ expect(isExpression.notOperator, isNull); |
+ expect(isExpression.type, isNotNull); |
+ } |
+ |
void test_parseRelationalExpression_isNot() { |
createParser('x is! y'); |
Expression expression = parser.parseRelationalExpression(); |
@@ -11751,6 +11850,18 @@ void'''); |
isNotNull); |
} |
+ @failingTest |
+ void test_parseStatement_functionDeclaration_noReturnType_typeParameters() { |
+ enableGenericMethods = true; |
+ createParser('f<E>(a, b) {};'); |
+ Statement statement = parser.parseStatement2(); |
+ expectNotNullIfNoErrors(statement); |
+ listener.assertNoErrors(); |
+ expect(statement, new isInstanceOf<FunctionDeclarationStatement>()); |
+ FunctionDeclarationStatement declaration = statement; |
+ expect(declaration.functionDeclaration, isNotNull); |
+ } |
+ |
void test_parseStatement_functionDeclaration_returnType() { |
// TODO(brianwilkerson) Implement more tests for this method. |
createParser('int f(a, b) {};'); |
@@ -12657,6 +12768,20 @@ void'''); |
expect(parameter.name, isNotNull); |
} |
+ void test_parseTypeParameter_bounded_nullable() { |
+ enableNnbd = true; |
+ createParser('A extends B?'); |
+ TypeParameter parameter = parser.parseTypeParameter(); |
+ expectNotNullIfNoErrors(parameter); |
+ listener.assertNoErrors(); |
+ expect(parameter.bound, isNotNull); |
+ expect(parameter.extendsKeyword, isNotNull); |
+ expect(parameter.name, isNotNull); |
+ TypeName bound = parameter.bound; |
+ expect(bound, isNotNull); |
+ expect(bound.question, isNotNull); |
+ } |
+ |
void test_parseTypeParameter_simple() { |
createParser('A'); |
TypeParameter parameter = parser.parseTypeParameter(); |