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

Side by Side Diff: pkg/analyzer/test/generated/parser_test.dart

Issue 1709013004: Improve error message (issue 25113) (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.test.generated.parser_test; 5 library analyzer.test.generated.parser_test;
6 6
7 import 'package:analyzer/dart/ast/ast.dart'; 7 import 'package:analyzer/dart/ast/ast.dart';
8 import 'package:analyzer/dart/ast/token.dart'; 8 import 'package:analyzer/dart/ast/token.dart';
9 import 'package:analyzer/dart/ast/visitor.dart'; 9 import 'package:analyzer/dart/ast/visitor.dart';
10 import 'package:analyzer/dart/element/element.dart'; 10 import 'package:analyzer/dart/element/element.dart';
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 ParserErrorCode.EXPECTED_TOKEN /*>*/, 1503 ParserErrorCode.EXPECTED_TOKEN /*>*/,
1504 ParserErrorCode.MISSING_IDENTIFIER, 1504 ParserErrorCode.MISSING_IDENTIFIER,
1505 ParserErrorCode.EXPECTED_TOKEN /*(*/, 1505 ParserErrorCode.EXPECTED_TOKEN /*(*/,
1506 ParserErrorCode.EXPECTED_TOKEN /*)*/, 1506 ParserErrorCode.EXPECTED_TOKEN /*)*/,
1507 ParserErrorCode.MISSING_FUNCTION_BODY 1507 ParserErrorCode.MISSING_FUNCTION_BODY
1508 ]); 1508 ]);
1509 expect(method.typeParameters.toString(), '<E, hello>', 1509 expect(method.typeParameters.toString(), '<E, hello>',
1510 reason: 'parser recovers what it can'); 1510 reason: 'parser recovers what it can');
1511 } 1511 }
1512 1512
1513 void test_method_invalidTypeParameters() {
1514 // TODO(jmesserly): ideally we'd be better at parser recovery here.
1515 // It doesn't try to advance past the invalid token `!` to find the
1516 // valid `>`. If it did we'd get less cascading errors, at least for this
1517 // particular example.
1518 enableGenericMethods = true;
1519 MethodDeclaration method = parse3(
1520 "parseClassMember",
1521 <Object>["C"],
1522 "void m<E, hello!>() {}",
1523 [
1524 ParserErrorCode.EXPECTED_TOKEN /*>*/,
1525 ParserErrorCode.MISSING_IDENTIFIER,
1526 ParserErrorCode.EXPECTED_TOKEN /*(*/,
1527 ParserErrorCode.EXPECTED_TOKEN /*)*/,
1528 ParserErrorCode.MISSING_FUNCTION_BODY
1529 ]);
1530 expect(method.typeParameters.toString(), '<E, hello>',
1531 reason: 'parser recovers what it can');
1532 }
1533
1534 void test_method_invalidTypeParameterExtends() { 1513 void test_method_invalidTypeParameterExtends() {
1535 // Regression test for https://github.com/dart-lang/sdk/issues/25739. 1514 // Regression test for https://github.com/dart-lang/sdk/issues/25739.
1536 1515
1537 // TODO(jmesserly): ideally we'd be better at parser recovery here. 1516 // TODO(jmesserly): ideally we'd be better at parser recovery here.
1538 enableGenericMethods = true; 1517 enableGenericMethods = true;
1539 MethodDeclaration method = parse3( 1518 MethodDeclaration method = parse3(
1540 "parseClassMember", 1519 "parseClassMember",
1541 <Object>["C"], 1520 <Object>["C"],
1542 "f<E>(E extends num p);", 1521 "f<E>(E extends num p);",
1543 [ 1522 [
1544 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword 1523 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword
1545 ParserErrorCode.EXPECTED_TOKEN, // comma 1524 ParserErrorCode.EXPECTED_TOKEN, // comma
1546 ParserErrorCode.EXPECTED_TOKEN, // close paren 1525 ParserErrorCode.EXPECTED_TOKEN, // close paren
1547 ParserErrorCode.MISSING_FUNCTION_BODY 1526 ParserErrorCode.MISSING_FUNCTION_BODY
1548 ]); 1527 ]);
1549 expect(method.parameters.toString(), '(E, extends)', 1528 expect(method.parameters.toString(), '(E, extends)',
1550 reason: 'parser recovers what it can'); 1529 reason: 'parser recovers what it can');
1551 } 1530 }
1552 1531
1553
1554 void test_method_invalidTypeParameterExtendsComment() { 1532 void test_method_invalidTypeParameterExtendsComment() {
1555 // Regression test for https://github.com/dart-lang/sdk/issues/25739. 1533 // Regression test for https://github.com/dart-lang/sdk/issues/25739.
1556 1534
1557 // TODO(jmesserly): ideally we'd be better at parser recovery here. 1535 // TODO(jmesserly): ideally we'd be better at parser recovery here.
1558 // Also, this behavior is slightly different from how we would parse a 1536 // Also, this behavior is slightly different from how we would parse a
1559 // normal generic method, because we "discover" the comment at a different 1537 // normal generic method, because we "discover" the comment at a different
1560 // point in the parser. This has a slight effect on the AST that results 1538 // point in the parser. This has a slight effect on the AST that results
1561 // from error recovery. 1539 // from error recovery.
1562 enableGenericMethodComments = true; 1540 enableGenericMethodComments = true;
1563 MethodDeclaration method = parse3( 1541 MethodDeclaration method = parse3(
1564 "parseClassMember", 1542 "parseClassMember",
1565 <Object>["C"], 1543 <Object>["C"],
1566 "f/*<E>*/(dynamic/*=E extends num*/p);", 1544 "f/*<E>*/(dynamic/*=E extends num*/p);",
1567 [ 1545 [
1568 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword 1546 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword
1569 ParserErrorCode.EXPECTED_TOKEN, // comma 1547 ParserErrorCode.EXPECTED_TOKEN, // comma
1570 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword 1548 ParserErrorCode.MISSING_IDENTIFIER, // `extends` is a keyword
1571 ParserErrorCode.EXPECTED_TOKEN, // close paren 1549 ParserErrorCode.EXPECTED_TOKEN, // close paren
1572 ParserErrorCode.MISSING_FUNCTION_BODY 1550 ParserErrorCode.MISSING_FUNCTION_BODY
1573 ]); 1551 ]);
1574 expect(method.parameters.toString(), '(E extends, extends)', 1552 expect(method.parameters.toString(), '(E extends, extends)',
1575 reason: 'parser recovers what it can'); 1553 reason: 'parser recovers what it can');
1576 } 1554 }
1577 1555
1556 void test_method_invalidTypeParameters() {
1557 // TODO(jmesserly): ideally we'd be better at parser recovery here.
1558 // It doesn't try to advance past the invalid token `!` to find the
1559 // valid `>`. If it did we'd get less cascading errors, at least for this
1560 // particular example.
1561 enableGenericMethods = true;
1562 MethodDeclaration method = parse3(
1563 "parseClassMember",
1564 <Object>["C"],
1565 "void m<E, hello!>() {}",
1566 [
1567 ParserErrorCode.EXPECTED_TOKEN /*>*/,
1568 ParserErrorCode.MISSING_IDENTIFIER,
1569 ParserErrorCode.EXPECTED_TOKEN /*(*/,
1570 ParserErrorCode.EXPECTED_TOKEN /*)*/,
1571 ParserErrorCode.MISSING_FUNCTION_BODY
1572 ]);
1573 expect(method.typeParameters.toString(), '<E, hello>',
1574 reason: 'parser recovers what it can');
1575 }
1576
1578 void test_missingAssignableSelector_identifiersAssigned() { 1577 void test_missingAssignableSelector_identifiersAssigned() {
1579 parseExpression("x.y = y;"); 1578 parseExpression("x.y = y;");
1580 } 1579 }
1581 1580
1582 void test_missingAssignableSelector_prefix_minusMinus_literal() { 1581 void test_missingAssignableSelector_prefix_minusMinus_literal() {
1583 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); 1582 parseExpression("--0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]);
1584 } 1583 }
1585 1584
1586 void test_missingAssignableSelector_prefix_plusPlus_literal() { 1585 void test_missingAssignableSelector_prefix_plusPlus_literal() {
1587 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]); 1586 parseExpression("++0", [ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR]);
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1941 void test_positionalAfterNamedArgument() { 1940 void test_positionalAfterNamedArgument() {
1942 parse4("parseArgumentList", "(x: 1, 2)", 1941 parse4("parseArgumentList", "(x: 1, 2)",
1943 [ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT]); 1942 [ParserErrorCode.POSITIONAL_AFTER_NAMED_ARGUMENT]);
1944 } 1943 }
1945 1944
1946 void test_positionalParameterOutsideGroup() { 1945 void test_positionalParameterOutsideGroup() {
1947 parse4("parseFormalParameterList", "(a, b = 0)", 1946 parse4("parseFormalParameterList", "(a, b = 0)",
1948 [ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP]); 1947 [ParserErrorCode.POSITIONAL_PARAMETER_OUTSIDE_GROUP]);
1949 } 1948 }
1950 1949
1950 void test_redirectingConstructorWithBody_named() {
1951 parse3("parseClassMember", <Object>["C"], "C.x() : this() {}",
1952 [ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY]);
1953 }
1954
1955 void test_redirectingConstructorWithBody_unnamed() {
1956 parse3("parseClassMember", <Object>["C"], "C() : this.x() {}",
1957 [ParserErrorCode.REDIRECTING_CONSTRUCTOR_WITH_BODY]);
1958 }
1959
1951 void test_redirectionInNonFactoryConstructor() { 1960 void test_redirectionInNonFactoryConstructor() {
1952 parse3("parseClassMember", <Object>["C"], "C() = D;", 1961 parse3("parseClassMember", <Object>["C"], "C() = D;",
1953 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]); 1962 [ParserErrorCode.REDIRECTION_IN_NON_FACTORY_CONSTRUCTOR]);
1954 } 1963 }
1955 1964
1956 void test_setterInFunction_block() { 1965 void test_setterInFunction_block() {
1957 ParserTestCase.parseStatement( 1966 ParserTestCase.parseStatement(
1958 "set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]); 1967 "set x(v) {_x = v;}", [ParserErrorCode.SETTER_IN_FUNCTION]);
1959 } 1968 }
1960 1969
(...skipping 9622 matching lines...) Expand 10 before | Expand all | Expand 10 after
11583 new Scanner(null, new CharSequenceReader(source), listener); 11592 new Scanner(null, new CharSequenceReader(source), listener);
11584 Token tokenStream = scanner.tokenize(); 11593 Token tokenStream = scanner.tokenize();
11585 // 11594 //
11586 // Parse the source. 11595 // Parse the source.
11587 // 11596 //
11588 Parser parser = new Parser(null, listener); 11597 Parser parser = new Parser(null, listener);
11589 return invokeParserMethodImpl( 11598 return invokeParserMethodImpl(
11590 parser, methodName, <Object>[tokenStream], tokenStream) as Token; 11599 parser, methodName, <Object>[tokenStream], tokenStream) as Token;
11591 } 11600 }
11592 } 11601 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698