| OLD | NEW |
| 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 engine.resolver.error_verifier; | 5 library engine.resolver.error_verifier; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'java_engine.dart'; | 10 import 'java_engine.dart'; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 _checkForInvalidCompoundAssignment(node, lhs, rhs); | 334 _checkForInvalidCompoundAssignment(node, lhs, rhs); |
| 335 _checkForArgumentTypeNotAssignableForArgument(rhs); | 335 _checkForArgumentTypeNotAssignableForArgument(rhs); |
| 336 } | 336 } |
| 337 _checkForAssignmentToFinal(lhs); | 337 _checkForAssignmentToFinal(lhs); |
| 338 return super.visitAssignmentExpression(node); | 338 return super.visitAssignmentExpression(node); |
| 339 } | 339 } |
| 340 | 340 |
| 341 @override | 341 @override |
| 342 Object visitAwaitExpression(AwaitExpression node) { | 342 Object visitAwaitExpression(AwaitExpression node) { |
| 343 if (!_inAsync) { | 343 if (!_inAsync) { |
| 344 _errorReporter.reportErrorForToken(CompileTimeErrorCode.AWAIT_IN_WRONG_CON
TEXT, node.awaitKeyword, []); | 344 _errorReporter.reportErrorForToken(CompileTimeErrorCode.AWAIT_IN_WRONG_CON
TEXT, node.awaitKeyword); |
| 345 } | 345 } |
| 346 return super.visitAwaitExpression(node); | 346 return super.visitAwaitExpression(node); |
| 347 } | 347 } |
| 348 | 348 |
| 349 @override | 349 @override |
| 350 Object visitBinaryExpression(BinaryExpression node) { | 350 Object visitBinaryExpression(BinaryExpression node) { |
| 351 sc.Token operator = node.operator; | 351 sc.Token operator = node.operator; |
| 352 sc.TokenType type = operator.type; | 352 sc.TokenType type = operator.type; |
| 353 if (type == sc.TokenType.AMPERSAND_AMPERSAND || type == sc.TokenType.BAR_BAR
) { | 353 if (type == sc.TokenType.AMPERSAND_AMPERSAND || type == sc.TokenType.BAR_BAR
) { |
| 354 String lexeme = operator.lexeme; | 354 String lexeme = operator.lexeme; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 384 } | 384 } |
| 385 return null; | 385 return null; |
| 386 } | 386 } |
| 387 | 387 |
| 388 @override | 388 @override |
| 389 Object visitBreakStatement(BreakStatement node) { | 389 Object visitBreakStatement(BreakStatement node) { |
| 390 SimpleIdentifier labelNode = node.label; | 390 SimpleIdentifier labelNode = node.label; |
| 391 if (labelNode != null) { | 391 if (labelNode != null) { |
| 392 Element labelElement = labelNode.staticElement; | 392 Element labelElement = labelNode.staticElement; |
| 393 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) { | 393 if (labelElement is LabelElementImpl && labelElement.isOnSwitchMember) { |
| 394 _errorReporter.reportErrorForNode(ResolverErrorCode.BREAK_LABEL_ON_SWITC
H_MEMBER, labelNode, []); | 394 _errorReporter.reportErrorForNode(ResolverErrorCode.BREAK_LABEL_ON_SWITC
H_MEMBER, labelNode); |
| 395 } | 395 } |
| 396 } | 396 } |
| 397 return null; | 397 return null; |
| 398 } | 398 } |
| 399 | 399 |
| 400 @override | 400 @override |
| 401 Object visitCatchClause(CatchClause node) { | 401 Object visitCatchClause(CatchClause node) { |
| 402 bool previousIsInCatchClause = _isInCatchClause; | 402 bool previousIsInCatchClause = _isInCatchClause; |
| 403 try { | 403 try { |
| 404 _isInCatchClause = true; | 404 _isInCatchClause = true; |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 _isInConstructorInitializer = false; | 545 _isInConstructorInitializer = false; |
| 546 } | 546 } |
| 547 } | 547 } |
| 548 | 548 |
| 549 @override | 549 @override |
| 550 Object visitContinueStatement(ContinueStatement node) { | 550 Object visitContinueStatement(ContinueStatement node) { |
| 551 SimpleIdentifier labelNode = node.label; | 551 SimpleIdentifier labelNode = node.label; |
| 552 if (labelNode != null) { | 552 if (labelNode != null) { |
| 553 Element labelElement = labelNode.staticElement; | 553 Element labelElement = labelNode.staticElement; |
| 554 if (labelElement is LabelElementImpl && labelElement.isOnSwitchStatement)
{ | 554 if (labelElement is LabelElementImpl && labelElement.isOnSwitchStatement)
{ |
| 555 _errorReporter.reportErrorForNode(ResolverErrorCode.CONTINUE_LABEL_ON_SW
ITCH, labelNode, []); | 555 _errorReporter.reportErrorForNode(ResolverErrorCode.CONTINUE_LABEL_ON_SW
ITCH, labelNode); |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 return null; | 558 return null; |
| 559 } | 559 } |
| 560 | 560 |
| 561 @override | 561 @override |
| 562 Object visitDefaultFormalParameter(DefaultFormalParameter node) { | 562 Object visitDefaultFormalParameter(DefaultFormalParameter node) { |
| 563 _checkForInvalidAssignment(node.identifier, node.defaultValue); | 563 _checkForInvalidAssignment(node.identifier, node.defaultValue); |
| 564 _checkForDefaultValueInFunctionTypedParameter(node); | 564 _checkForDefaultValueInFunctionTypedParameter(node); |
| 565 return super.visitDefaultFormalParameter(node); | 565 return super.visitDefaultFormalParameter(node); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 } | 600 } |
| 601 } | 601 } |
| 602 | 602 |
| 603 @override | 603 @override |
| 604 Object visitFieldDeclaration(FieldDeclaration node) { | 604 Object visitFieldDeclaration(FieldDeclaration node) { |
| 605 _isInStaticVariableDeclaration = node.isStatic; | 605 _isInStaticVariableDeclaration = node.isStatic; |
| 606 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; | 606 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; |
| 607 if (_isInInstanceVariableDeclaration) { | 607 if (_isInInstanceVariableDeclaration) { |
| 608 VariableDeclarationList variables = node.fields; | 608 VariableDeclarationList variables = node.fields; |
| 609 if (variables.isConst) { | 609 if (variables.isConst) { |
| 610 _errorReporter.reportErrorForToken(CompileTimeErrorCode.CONST_INSTANCE_F
IELD, variables.keyword, []); | 610 _errorReporter.reportErrorForToken(CompileTimeErrorCode.CONST_INSTANCE_F
IELD, variables.keyword); |
| 611 } | 611 } |
| 612 } | 612 } |
| 613 try { | 613 try { |
| 614 _checkForAllInvalidOverrideErrorCodesForField(node); | 614 _checkForAllInvalidOverrideErrorCodesForField(node); |
| 615 return super.visitFieldDeclaration(node); | 615 return super.visitFieldDeclaration(node); |
| 616 } finally { | 616 } finally { |
| 617 _isInStaticVariableDeclaration = false; | 617 _isInStaticVariableDeclaration = false; |
| 618 _isInInstanceVariableDeclaration = false; | 618 _isInInstanceVariableDeclaration = false; |
| 619 } | 619 } |
| 620 } | 620 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } else { | 675 } else { |
| 676 return super.visitFunctionExpression(node); | 676 return super.visitFunctionExpression(node); |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 | 679 |
| 680 @override | 680 @override |
| 681 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { | 681 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { |
| 682 Expression functionExpression = node.function; | 682 Expression functionExpression = node.function; |
| 683 DartType expressionType = functionExpression.staticType; | 683 DartType expressionType = functionExpression.staticType; |
| 684 if (!_isFunctionType(expressionType)) { | 684 if (!_isFunctionType(expressionType)) { |
| 685 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVOCATION_OF_NON_
FUNCTION_EXPRESSION, functionExpression, []); | 685 _errorReporter.reportErrorForNode(StaticTypeWarningCode.INVOCATION_OF_NON_
FUNCTION_EXPRESSION, functionExpression); |
| 686 } | 686 } |
| 687 return super.visitFunctionExpressionInvocation(node); | 687 return super.visitFunctionExpressionInvocation(node); |
| 688 } | 688 } |
| 689 | 689 |
| 690 @override | 690 @override |
| 691 Object visitFunctionTypeAlias(FunctionTypeAlias node) { | 691 Object visitFunctionTypeAlias(FunctionTypeAlias node) { |
| 692 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID
ENTIFIER_AS_TYPEDEF_NAME); | 692 _checkForBuiltInIdentifierAsName(node.name, CompileTimeErrorCode.BUILT_IN_ID
ENTIFIER_AS_TYPEDEF_NAME); |
| 693 _checkForDefaultValueInFunctionTypeAlias(node); | 693 _checkForDefaultValueInFunctionTypeAlias(node); |
| 694 _checkForTypeAliasCannotReferenceItself_function(node); | 694 _checkForTypeAliasCannotReferenceItself_function(node); |
| 695 return super.visitFunctionTypeAlias(node); | 695 return super.visitFunctionTypeAlias(node); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 } else { | 844 } else { |
| 845 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); | 845 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); |
| 846 } | 846 } |
| 847 return super.visitMethodInvocation(node); | 847 return super.visitMethodInvocation(node); |
| 848 } | 848 } |
| 849 | 849 |
| 850 @override | 850 @override |
| 851 Object visitNativeClause(NativeClause node) { | 851 Object visitNativeClause(NativeClause node) { |
| 852 // TODO(brianwilkerson) Figure out the right rule for when 'native' is allow
ed. | 852 // TODO(brianwilkerson) Figure out the right rule for when 'native' is allow
ed. |
| 853 if (!_isInSystemLibrary) { | 853 if (!_isInSystemLibrary) { |
| 854 _errorReporter.reportErrorForNode(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK
_CODE, node, []); | 854 _errorReporter.reportErrorForNode(ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK
_CODE, node); |
| 855 } | 855 } |
| 856 return super.visitNativeClause(node); | 856 return super.visitNativeClause(node); |
| 857 } | 857 } |
| 858 | 858 |
| 859 @override | 859 @override |
| 860 Object visitNativeFunctionBody(NativeFunctionBody node) { | 860 Object visitNativeFunctionBody(NativeFunctionBody node) { |
| 861 _checkForNativeFunctionBodyInNonSDKCode(node); | 861 _checkForNativeFunctionBodyInNonSDKCode(node); |
| 862 return super.visitNativeFunctionBody(node); | 862 return super.visitNativeFunctionBody(node); |
| 863 } | 863 } |
| 864 | 864 |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1051 | 1051 |
| 1052 @override | 1052 @override |
| 1053 Object visitYieldStatement(YieldStatement node) { | 1053 Object visitYieldStatement(YieldStatement node) { |
| 1054 if (!_inGenerator) { | 1054 if (!_inGenerator) { |
| 1055 CompileTimeErrorCode errorCode; | 1055 CompileTimeErrorCode errorCode; |
| 1056 if (node.star != null) { | 1056 if (node.star != null) { |
| 1057 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; | 1057 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; |
| 1058 } else { | 1058 } else { |
| 1059 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; | 1059 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; |
| 1060 } | 1060 } |
| 1061 _errorReporter.reportErrorForNode(errorCode, node, []); | 1061 _errorReporter.reportErrorForNode(errorCode, node); |
| 1062 } | 1062 } |
| 1063 return super.visitYieldStatement(node); | 1063 return super.visitYieldStatement(node); |
| 1064 } | 1064 } |
| 1065 | 1065 |
| 1066 /** | 1066 /** |
| 1067 * This verifies if the passed map literal has type arguments then there is ex
actly two. | 1067 * This verifies if the passed map literal has type arguments then there is ex
actly two. |
| 1068 * | 1068 * |
| 1069 * @param typeArguments the type arguments, always non-`null` | 1069 * @param typeArguments the type arguments, always non-`null` |
| 1070 * @return `true` if and only if an error code is generated on the passed node | 1070 * @return `true` if and only if an error code is generated on the passed node |
| 1071 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. | 1071 * See [StaticTypeWarningCode.EXPECTED_TWO_MAP_TYPE_ARGUMENTS]. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 ConstructorFieldInitializer constructorFieldInitializer = constructorIni
tializer; | 1136 ConstructorFieldInitializer constructorFieldInitializer = constructorIni
tializer; |
| 1137 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; | 1137 SimpleIdentifier fieldName = constructorFieldInitializer.fieldName; |
| 1138 Element element = fieldName.staticElement; | 1138 Element element = fieldName.staticElement; |
| 1139 if (element is FieldElement) { | 1139 if (element is FieldElement) { |
| 1140 FieldElement fieldElement = element; | 1140 FieldElement fieldElement = element; |
| 1141 INIT_STATE state = fieldElementsMap[fieldElement]; | 1141 INIT_STATE state = fieldElementsMap[fieldElement]; |
| 1142 if (state == INIT_STATE.NOT_INIT) { | 1142 if (state == INIT_STATE.NOT_INIT) { |
| 1143 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; | 1143 fieldElementsMap[fieldElement] = INIT_STATE.INIT_IN_INITIALIZERS; |
| 1144 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { | 1144 } else if (state == INIT_STATE.INIT_IN_DECLARATION) { |
| 1145 if (fieldElement.isFinal || fieldElement.isConst) { | 1145 if (fieldElement.isFinal || fieldElement.isConst) { |
| 1146 _errorReporter.reportErrorForNode(StaticWarningCode.FIELD_INITIALI
ZED_IN_INITIALIZER_AND_DECLARATION, fieldName, []); | 1146 _errorReporter.reportErrorForNode(StaticWarningCode.FIELD_INITIALI
ZED_IN_INITIALIZER_AND_DECLARATION, fieldName); |
| 1147 foundError = true; | 1147 foundError = true; |
| 1148 } | 1148 } |
| 1149 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { | 1149 } else if (state == INIT_STATE.INIT_IN_FIELD_FORMAL) { |
| 1150 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL
IZED_IN_PARAMETER_AND_INITIALIZER, fieldName, []); | 1150 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL
IZED_IN_PARAMETER_AND_INITIALIZER, fieldName); |
| 1151 foundError = true; | 1151 foundError = true; |
| 1152 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { | 1152 } else if (state == INIT_STATE.INIT_IN_INITIALIZERS) { |
| 1153 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL
IZED_BY_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); | 1153 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIAL
IZED_BY_MULTIPLE_INITIALIZERS, fieldName, [fieldElement.displayName]); |
| 1154 foundError = true; | 1154 foundError = true; |
| 1155 } | 1155 } |
| 1156 } | 1156 } |
| 1157 } | 1157 } |
| 1158 } | 1158 } |
| 1159 // Visit all of the states in the map to ensure that none were never | 1159 // Visit all of the states in the map to ensure that none were never |
| 1160 // initialized. | 1160 // initialized. |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1633 bool _checkForAllReturnStatementErrorCodes(ReturnStatement node) { | 1633 bool _checkForAllReturnStatementErrorCodes(ReturnStatement node) { |
| 1634 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; | 1634 FunctionType functionType = _enclosingFunction == null ? null : _enclosingFu
nction.type; |
| 1635 DartType expectedReturnType = functionType == null ? DynamicTypeImpl.instanc
e : functionType.returnType; | 1635 DartType expectedReturnType = functionType == null ? DynamicTypeImpl.instanc
e : functionType.returnType; |
| 1636 Expression returnExpression = node.expression; | 1636 Expression returnExpression = node.expression; |
| 1637 // RETURN_IN_GENERATIVE_CONSTRUCTOR | 1637 // RETURN_IN_GENERATIVE_CONSTRUCTOR |
| 1638 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && !
(_enclosingFunction as ConstructorElement).isFactory; | 1638 bool isGenerativeConstructor = _enclosingFunction is ConstructorElement && !
(_enclosingFunction as ConstructorElement).isFactory; |
| 1639 if (isGenerativeConstructor) { | 1639 if (isGenerativeConstructor) { |
| 1640 if (returnExpression == null) { | 1640 if (returnExpression == null) { |
| 1641 return false; | 1641 return false; |
| 1642 } | 1642 } |
| 1643 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIV
E_CONSTRUCTOR, returnExpression, []); | 1643 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIV
E_CONSTRUCTOR, returnExpression); |
| 1644 return true; | 1644 return true; |
| 1645 } | 1645 } |
| 1646 // RETURN_WITHOUT_VALUE | 1646 // RETURN_WITHOUT_VALUE |
| 1647 if (returnExpression == null) { | 1647 if (returnExpression == null) { |
| 1648 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { | 1648 if (VoidTypeImpl.instance.isAssignableTo(expectedReturnType)) { |
| 1649 return false; | 1649 return false; |
| 1650 } | 1650 } |
| 1651 _hasReturnWithoutValue = true; | 1651 _hasReturnWithoutValue = true; |
| 1652 _errorReporter.reportErrorForNode(StaticWarningCode.RETURN_WITHOUT_VALUE,
node, []); | 1652 _errorReporter.reportErrorForNode(StaticWarningCode.RETURN_WITHOUT_VALUE,
node); |
| 1653 return true; | 1653 return true; |
| 1654 } else if (_inGenerator) { | 1654 } else if (_inGenerator) { |
| 1655 // RETURN_IN_GENERATOR | 1655 // RETURN_IN_GENERATOR |
| 1656 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATOR
, node, []); | 1656 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATOR
, node); |
| 1657 } | 1657 } |
| 1658 // RETURN_OF_INVALID_TYPE | 1658 // RETURN_OF_INVALID_TYPE |
| 1659 return _checkForReturnOfInvalidType(returnExpression, expectedReturnType); | 1659 return _checkForReturnOfInvalidType(returnExpression, expectedReturnType); |
| 1660 } | 1660 } |
| 1661 | 1661 |
| 1662 /** | 1662 /** |
| 1663 * This verifies that the export namespace of the passed export directive does
not export any name | 1663 * This verifies that the export namespace of the passed export directive does
not export any name |
| 1664 * already exported by other export directive. | 1664 * already exported by other export directive. |
| 1665 * | 1665 * |
| 1666 * @param node the export directive node to report problem on | 1666 * @param node the export directive node to report problem on |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 highlightedNode = propertyAccess.propertyName; | 1835 highlightedNode = propertyAccess.propertyName; |
| 1836 } | 1836 } |
| 1837 // check if element is assignable | 1837 // check if element is assignable |
| 1838 if (element is PropertyAccessorElement) { | 1838 if (element is PropertyAccessorElement) { |
| 1839 PropertyAccessorElement accessor = element as PropertyAccessorElement; | 1839 PropertyAccessorElement accessor = element as PropertyAccessorElement; |
| 1840 element = accessor.variable; | 1840 element = accessor.variable; |
| 1841 } | 1841 } |
| 1842 if (element is VariableElement) { | 1842 if (element is VariableElement) { |
| 1843 VariableElement variable = element as VariableElement; | 1843 VariableElement variable = element as VariableElement; |
| 1844 if (variable.isConst) { | 1844 if (variable.isConst) { |
| 1845 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST,
expression, []); | 1845 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_CONST,
expression); |
| 1846 return true; | 1846 return true; |
| 1847 } | 1847 } |
| 1848 if (variable.isFinal) { | 1848 if (variable.isFinal) { |
| 1849 if (variable is FieldElementImpl && variable.setter == null && variable.
isSynthetic) { | 1849 if (variable is FieldElementImpl && variable.setter == null && variable.
isSynthetic) { |
| 1850 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINA
L_NO_SETTER, highlightedNode, [variable.name, variable.enclosingElement.displayN
ame]); | 1850 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINA
L_NO_SETTER, highlightedNode, [variable.name, variable.enclosingElement.displayN
ame]); |
| 1851 return true; | 1851 return true; |
| 1852 } | 1852 } |
| 1853 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL,
highlightedNode, [variable.name]); | 1853 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FINAL,
highlightedNode, [variable.name]); |
| 1854 return true; | 1854 return true; |
| 1855 } | 1855 } |
| 1856 return false; | 1856 return false; |
| 1857 } | 1857 } |
| 1858 if (element is FunctionElement) { | 1858 if (element is FunctionElement) { |
| 1859 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FUNCTION
, expression, []); | 1859 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_FUNCTION
, expression); |
| 1860 return true; | 1860 return true; |
| 1861 } | 1861 } |
| 1862 if (element is MethodElement) { | 1862 if (element is MethodElement) { |
| 1863 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_METHOD,
expression, []); | 1863 _errorReporter.reportErrorForNode(StaticWarningCode.ASSIGNMENT_TO_METHOD,
expression); |
| 1864 return true; | 1864 return true; |
| 1865 } | 1865 } |
| 1866 return false; | 1866 return false; |
| 1867 } | 1867 } |
| 1868 | 1868 |
| 1869 /** | 1869 /** |
| 1870 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code | 1870 * This verifies that the passed identifier is not a keyword, and generates th
e passed error code |
| 1871 * on the identifier if it is a keyword. | 1871 * on the identifier if it is a keyword. |
| 1872 * | 1872 * |
| 1873 * @param identifier the identifier to check to ensure that it is not a keywor
d | 1873 * @param identifier the identifier to check to ensure that it is not a keywor
d |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1920 } | 1920 } |
| 1921 // terminated with 'throw' expression | 1921 // terminated with 'throw' expression |
| 1922 if (statement is ExpressionStatement) { | 1922 if (statement is ExpressionStatement) { |
| 1923 Expression expression = statement.expression; | 1923 Expression expression = statement.expression; |
| 1924 if (expression is ThrowExpression) { | 1924 if (expression is ThrowExpression) { |
| 1925 return false; | 1925 return false; |
| 1926 } | 1926 } |
| 1927 } | 1927 } |
| 1928 } | 1928 } |
| 1929 // report error | 1929 // report error |
| 1930 _errorReporter.reportErrorForToken(StaticWarningCode.CASE_BLOCK_NOT_TERMINAT
ED, node.keyword, []); | 1930 _errorReporter.reportErrorForToken(StaticWarningCode.CASE_BLOCK_NOT_TERMINAT
ED, node.keyword); |
| 1931 return true; | 1931 return true; |
| 1932 } | 1932 } |
| 1933 | 1933 |
| 1934 /** | 1934 /** |
| 1935 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', | 1935 * This verifies that the switch cases in the given switch statement is termin
ated with 'break', |
| 1936 * 'continue', 'return' or 'throw'. | 1936 * 'continue', 'return' or 'throw'. |
| 1937 * | 1937 * |
| 1938 * @param node the switch statement containing the cases to be checked | 1938 * @param node the switch statement containing the cases to be checked |
| 1939 * @return `true` if and only if an error code is generated on the passed node | 1939 * @return `true` if and only if an error code is generated on the passed node |
| 1940 * See [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]. | 1940 * See [StaticWarningCode.CASE_BLOCK_NOT_TERMINATED]. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1997 String name = constructorElement.name; | 1997 String name = constructorElement.name; |
| 1998 ClassElement classElement = constructorElement.enclosingElement; | 1998 ClassElement classElement = constructorElement.enclosingElement; |
| 1999 // constructors | 1999 // constructors |
| 2000 List<ConstructorElement> constructors = classElement.constructors; | 2000 List<ConstructorElement> constructors = classElement.constructors; |
| 2001 for (ConstructorElement otherConstructor in constructors) { | 2001 for (ConstructorElement otherConstructor in constructors) { |
| 2002 if (identical(otherConstructor, constructorElement)) { | 2002 if (identical(otherConstructor, constructorElement)) { |
| 2003 continue; | 2003 continue; |
| 2004 } | 2004 } |
| 2005 if (name == otherConstructor.name) { | 2005 if (name == otherConstructor.name) { |
| 2006 if (name == null || name.length == 0) { | 2006 if (name == null || name.length == 0) { |
| 2007 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DUPLICATE_CONST
RUCTOR_DEFAULT, node, []); | 2007 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DUPLICATE_CONST
RUCTOR_DEFAULT, node); |
| 2008 } else { | 2008 } else { |
| 2009 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DUPLICATE_CONST
RUCTOR_NAME, node, [name]); | 2009 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DUPLICATE_CONST
RUCTOR_NAME, node, [name]); |
| 2010 } | 2010 } |
| 2011 return true; | 2011 return true; |
| 2012 } | 2012 } |
| 2013 } | 2013 } |
| 2014 // conflict with class member | 2014 // conflict with class member |
| 2015 if (constructorName != null && constructorElement != null && !constructorNam
e.isSynthetic) { | 2015 if (constructorName != null && constructorElement != null && !constructorNam
e.isSynthetic) { |
| 2016 // fields | 2016 // fields |
| 2017 FieldElement field = classElement.getField(name); | 2017 FieldElement field = classElement.getField(name); |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2346 bool _checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) { | 2346 bool _checkForConstConstructorWithNonConstSuper(ConstructorDeclaration node) { |
| 2347 if (!_isEnclosingConstructorConst) { | 2347 if (!_isEnclosingConstructorConst) { |
| 2348 return false; | 2348 return false; |
| 2349 } | 2349 } |
| 2350 // OK, const factory, checked elsewhere | 2350 // OK, const factory, checked elsewhere |
| 2351 if (node.factoryKeyword != null) { | 2351 if (node.factoryKeyword != null) { |
| 2352 return false; | 2352 return false; |
| 2353 } | 2353 } |
| 2354 // check for mixins | 2354 // check for mixins |
| 2355 if (_enclosingClass.mixins.length != 0) { | 2355 if (_enclosingClass.mixins.length != 0) { |
| 2356 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_W
ITH_MIXIN, node.returnType, []); | 2356 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_W
ITH_MIXIN, node.returnType); |
| 2357 return true; | 2357 return true; |
| 2358 } | 2358 } |
| 2359 // try to find and check super constructor invocation | 2359 // try to find and check super constructor invocation |
| 2360 for (ConstructorInitializer initializer in node.initializers) { | 2360 for (ConstructorInitializer initializer in node.initializers) { |
| 2361 if (initializer is SuperConstructorInvocation) { | 2361 if (initializer is SuperConstructorInvocation) { |
| 2362 SuperConstructorInvocation superInvocation = initializer; | 2362 SuperConstructorInvocation superInvocation = initializer; |
| 2363 ConstructorElement element = superInvocation.staticElement; | 2363 ConstructorElement element = superInvocation.staticElement; |
| 2364 if (element == null || element.isConst) { | 2364 if (element == null || element.isConst) { |
| 2365 return false; | 2365 return false; |
| 2366 } | 2366 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2400 bool _checkForConstConstructorWithNonFinalField(ConstructorDeclaration node, C
onstructorElement constructorElement) { | 2400 bool _checkForConstConstructorWithNonFinalField(ConstructorDeclaration node, C
onstructorElement constructorElement) { |
| 2401 if (!_isEnclosingConstructorConst) { | 2401 if (!_isEnclosingConstructorConst) { |
| 2402 return false; | 2402 return false; |
| 2403 } | 2403 } |
| 2404 // check if there is non-final field | 2404 // check if there is non-final field |
| 2405 ClassElement classElement = constructorElement.enclosingElement; | 2405 ClassElement classElement = constructorElement.enclosingElement; |
| 2406 if (!classElement.hasNonFinalField) { | 2406 if (!classElement.hasNonFinalField) { |
| 2407 return false; | 2407 return false; |
| 2408 } | 2408 } |
| 2409 // report problem | 2409 // report problem |
| 2410 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT
H_NON_FINAL_FIELD, node, []); | 2410 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_WIT
H_NON_FINAL_FIELD, node); |
| 2411 return true; | 2411 return true; |
| 2412 } | 2412 } |
| 2413 | 2413 |
| 2414 /** | 2414 /** |
| 2415 * This verifies that the passed 'const' instance creation expression is not c
reating a deferred | 2415 * This verifies that the passed 'const' instance creation expression is not c
reating a deferred |
| 2416 * type. | 2416 * type. |
| 2417 * | 2417 * |
| 2418 * @param node the instance creation expression to evaluate | 2418 * @param node the instance creation expression to evaluate |
| 2419 * @param constructorName the constructor name, always non-`null` | 2419 * @param constructorName the constructor name, always non-`null` |
| 2420 * @param typeName the name of the type defining the constructor, always non-`
null` | 2420 * @param typeName the name of the type defining the constructor, always non-`
null` |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2432 /** | 2432 /** |
| 2433 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor | 2433 * This verifies that the passed throw expression is not enclosed in a 'const'
constructor |
| 2434 * declaration. | 2434 * declaration. |
| 2435 * | 2435 * |
| 2436 * @param node the throw expression expression to evaluate | 2436 * @param node the throw expression expression to evaluate |
| 2437 * @return `true` if and only if an error code is generated on the passed node | 2437 * @return `true` if and only if an error code is generated on the passed node |
| 2438 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]. | 2438 * See [CompileTimeErrorCode.CONST_CONSTRUCTOR_THROWS_EXCEPTION]. |
| 2439 */ | 2439 */ |
| 2440 bool _checkForConstEvalThrowsException(ThrowExpression node) { | 2440 bool _checkForConstEvalThrowsException(ThrowExpression node) { |
| 2441 if (_isEnclosingConstructorConst) { | 2441 if (_isEnclosingConstructorConst) { |
| 2442 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_T
HROWS_EXCEPTION, node, []); | 2442 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_CONSTRUCTOR_T
HROWS_EXCEPTION, node); |
| 2443 return true; | 2443 return true; |
| 2444 } | 2444 } |
| 2445 return false; | 2445 return false; |
| 2446 } | 2446 } |
| 2447 | 2447 |
| 2448 /** | 2448 /** |
| 2449 * This verifies that the passed normal formal parameter is not 'const'. | 2449 * This verifies that the passed normal formal parameter is not 'const'. |
| 2450 * | 2450 * |
| 2451 * @param node the normal formal parameter to evaluate | 2451 * @param node the normal formal parameter to evaluate |
| 2452 * @return `true` if and only if an error code is generated on the passed node | 2452 * @return `true` if and only if an error code is generated on the passed node |
| 2453 * See [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]. | 2453 * See [CompileTimeErrorCode.CONST_FORMAL_PARAMETER]. |
| 2454 */ | 2454 */ |
| 2455 bool _checkForConstFormalParameter(NormalFormalParameter node) { | 2455 bool _checkForConstFormalParameter(NormalFormalParameter node) { |
| 2456 if (node.isConst) { | 2456 if (node.isConst) { |
| 2457 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FORMAL_PARAME
TER, node, []); | 2457 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_FORMAL_PARAME
TER, node); |
| 2458 return true; | 2458 return true; |
| 2459 } | 2459 } |
| 2460 return false; | 2460 return false; |
| 2461 } | 2461 } |
| 2462 | 2462 |
| 2463 /** | 2463 /** |
| 2464 * This verifies that the passed instance creation expression is not being inv
oked on an abstract | 2464 * This verifies that the passed instance creation expression is not being inv
oked on an abstract |
| 2465 * class. | 2465 * class. |
| 2466 * | 2466 * |
| 2467 * @param node the instance creation expression to evaluate | 2467 * @param node the instance creation expression to evaluate |
| 2468 * @param typeName the [TypeName] of the [ConstructorName] from the | 2468 * @param typeName the [TypeName] of the [ConstructorName] from the |
| 2469 * [InstanceCreationExpression], this is the AST node that the error
is attached to | 2469 * [InstanceCreationExpression], this is the AST node that the error
is attached to |
| 2470 * @param type the type being constructed with this [InstanceCreationExpressio
n] | 2470 * @param type the type being constructed with this [InstanceCreationExpressio
n] |
| 2471 * @return `true` if and only if an error code is generated on the passed node | 2471 * @return `true` if and only if an error code is generated on the passed node |
| 2472 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and | 2472 * See [StaticWarningCode.CONST_WITH_ABSTRACT_CLASS], and |
| 2473 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. | 2473 * [StaticWarningCode.NEW_WITH_ABSTRACT_CLASS]. |
| 2474 */ | 2474 */ |
| 2475 bool _checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Typ
eName typeName, InterfaceType type) { | 2475 bool _checkForConstOrNewWithAbstractClass(InstanceCreationExpression node, Typ
eName typeName, InterfaceType type) { |
| 2476 if (type.element.isAbstract) { | 2476 if (type.element.isAbstract) { |
| 2477 ConstructorElement element = node.staticElement; | 2477 ConstructorElement element = node.staticElement; |
| 2478 if (element != null && !element.isFactory) { | 2478 if (element != null && !element.isFactory) { |
| 2479 if ((node.keyword as sc.KeywordToken).keyword == sc.Keyword.CONST) { | 2479 if ((node.keyword as sc.KeywordToken).keyword == sc.Keyword.CONST) { |
| 2480 _errorReporter.reportErrorForNode(StaticWarningCode.CONST_WITH_ABSTRAC
T_CLASS, typeName, []); | 2480 _errorReporter.reportErrorForNode(StaticWarningCode.CONST_WITH_ABSTRAC
T_CLASS, typeName); |
| 2481 } else { | 2481 } else { |
| 2482 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_ABSTRACT_
CLASS, typeName, []); | 2482 _errorReporter.reportErrorForNode(StaticWarningCode.NEW_WITH_ABSTRACT_
CLASS, typeName); |
| 2483 } | 2483 } |
| 2484 return true; | 2484 return true; |
| 2485 } | 2485 } |
| 2486 } | 2486 } |
| 2487 return false; | 2487 return false; |
| 2488 } | 2488 } |
| 2489 | 2489 |
| 2490 /** | 2490 /** |
| 2491 * This verifies that the passed instance creation expression is not being inv
oked on an enum. | 2491 * This verifies that the passed instance creation expression is not being inv
oked on an enum. |
| 2492 * | 2492 * |
| 2493 * @param node the instance creation expression to verify | 2493 * @param node the instance creation expression to verify |
| 2494 * @param typeName the [TypeName] of the [ConstructorName] from the | 2494 * @param typeName the [TypeName] of the [ConstructorName] from the |
| 2495 * [InstanceCreationExpression], this is the AST node that the error
is attached to | 2495 * [InstanceCreationExpression], this is the AST node that the error
is attached to |
| 2496 * @param type the type being constructed with this [InstanceCreationExpressio
n] | 2496 * @param type the type being constructed with this [InstanceCreationExpressio
n] |
| 2497 * @return `true` if and only if an error code is generated on the passed node | 2497 * @return `true` if and only if an error code is generated on the passed node |
| 2498 * See [CompileTimeErrorCode.INSTANTIATE_ENUM]. | 2498 * See [CompileTimeErrorCode.INSTANTIATE_ENUM]. |
| 2499 */ | 2499 */ |
| 2500 bool _checkForConstOrNewWithEnum(InstanceCreationExpression node, TypeName typ
eName, InterfaceType type) { | 2500 bool _checkForConstOrNewWithEnum(InstanceCreationExpression node, TypeName typ
eName, InterfaceType type) { |
| 2501 if (type.element.isEnum) { | 2501 if (type.element.isEnum) { |
| 2502 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANTIATE_ENUM, t
ypeName, []); | 2502 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANTIATE_ENUM, t
ypeName); |
| 2503 return true; | 2503 return true; |
| 2504 } | 2504 } |
| 2505 return false; | 2505 return false; |
| 2506 } | 2506 } |
| 2507 | 2507 |
| 2508 /** | 2508 /** |
| 2509 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a | 2509 * This verifies that the passed 'const' instance creation expression is not b
eing invoked on a |
| 2510 * constructor that is not 'const'. | 2510 * constructor that is not 'const'. |
| 2511 * | 2511 * |
| 2512 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. | 2512 * This method assumes that the instance creation was tested to be 'const' bef
ore being called. |
| 2513 * | 2513 * |
| 2514 * @param node the instance creation expression to verify | 2514 * @param node the instance creation expression to verify |
| 2515 * @return `true` if and only if an error code is generated on the passed node | 2515 * @return `true` if and only if an error code is generated on the passed node |
| 2516 * See [CompileTimeErrorCode.CONST_WITH_NON_CONST]. | 2516 * See [CompileTimeErrorCode.CONST_WITH_NON_CONST]. |
| 2517 */ | 2517 */ |
| 2518 bool _checkForConstWithNonConst(InstanceCreationExpression node) { | 2518 bool _checkForConstWithNonConst(InstanceCreationExpression node) { |
| 2519 ConstructorElement constructorElement = node.staticElement; | 2519 ConstructorElement constructorElement = node.staticElement; |
| 2520 if (constructorElement != null && !constructorElement.isConst) { | 2520 if (constructorElement != null && !constructorElement.isConst) { |
| 2521 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_CONS
T, node, []); | 2521 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_NON_CONS
T, node); |
| 2522 return true; | 2522 return true; |
| 2523 } | 2523 } |
| 2524 return false; | 2524 return false; |
| 2525 } | 2525 } |
| 2526 | 2526 |
| 2527 /** | 2527 /** |
| 2528 * This verifies that the passed type name does not reference any type paramet
ers. | 2528 * This verifies that the passed type name does not reference any type paramet
ers. |
| 2529 * | 2529 * |
| 2530 * @param typeName the type name to evaluate | 2530 * @param typeName the type name to evaluate |
| 2531 * @return `true` if and only if an error code is generated on the passed node | 2531 * @return `true` if and only if an error code is generated on the passed node |
| 2532 * See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS]. | 2532 * See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS]. |
| 2533 */ | 2533 */ |
| 2534 bool _checkForConstWithTypeParameters(TypeName typeName) { | 2534 bool _checkForConstWithTypeParameters(TypeName typeName) { |
| 2535 // something wrong with AST | 2535 // something wrong with AST |
| 2536 if (typeName == null) { | 2536 if (typeName == null) { |
| 2537 return false; | 2537 return false; |
| 2538 } | 2538 } |
| 2539 Identifier name = typeName.name; | 2539 Identifier name = typeName.name; |
| 2540 if (name == null) { | 2540 if (name == null) { |
| 2541 return false; | 2541 return false; |
| 2542 } | 2542 } |
| 2543 // should not be a type parameter | 2543 // should not be a type parameter |
| 2544 if (name.staticElement is TypeParameterElement) { | 2544 if (name.staticElement is TypeParameterElement) { |
| 2545 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_TYPE_PAR
AMETERS, name, []); | 2545 _errorReporter.reportErrorForNode(CompileTimeErrorCode.CONST_WITH_TYPE_PAR
AMETERS, name); |
| 2546 } | 2546 } |
| 2547 // check type arguments | 2547 // check type arguments |
| 2548 TypeArgumentList typeArguments = typeName.typeArguments; | 2548 TypeArgumentList typeArguments = typeName.typeArguments; |
| 2549 if (typeArguments != null) { | 2549 if (typeArguments != null) { |
| 2550 bool hasError = false; | 2550 bool hasError = false; |
| 2551 for (TypeName argument in typeArguments.arguments) { | 2551 for (TypeName argument in typeArguments.arguments) { |
| 2552 if (_checkForConstWithTypeParameters(argument)) { | 2552 if (_checkForConstWithTypeParameters(argument)) { |
| 2553 hasError = true; | 2553 hasError = true; |
| 2554 } | 2554 } |
| 2555 } | 2555 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2604 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. | 2604 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPE_ALIAS]. |
| 2605 */ | 2605 */ |
| 2606 bool _checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { | 2606 bool _checkForDefaultValueInFunctionTypeAlias(FunctionTypeAlias node) { |
| 2607 bool result = false; | 2607 bool result = false; |
| 2608 FormalParameterList formalParameterList = node.parameters; | 2608 FormalParameterList formalParameterList = node.parameters; |
| 2609 NodeList<FormalParameter> parameters = formalParameterList.parameters; | 2609 NodeList<FormalParameter> parameters = formalParameterList.parameters; |
| 2610 for (FormalParameter formalParameter in parameters) { | 2610 for (FormalParameter formalParameter in parameters) { |
| 2611 if (formalParameter is DefaultFormalParameter) { | 2611 if (formalParameter is DefaultFormalParameter) { |
| 2612 DefaultFormalParameter defaultFormalParameter = formalParameter; | 2612 DefaultFormalParameter defaultFormalParameter = formalParameter; |
| 2613 if (defaultFormalParameter.defaultValue != null) { | 2613 if (defaultFormalParameter.defaultValue != null) { |
| 2614 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I
N_FUNCTION_TYPE_ALIAS, node, []); | 2614 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I
N_FUNCTION_TYPE_ALIAS, node); |
| 2615 result = true; | 2615 result = true; |
| 2616 } | 2616 } |
| 2617 } | 2617 } |
| 2618 } | 2618 } |
| 2619 return result; | 2619 return result; |
| 2620 } | 2620 } |
| 2621 | 2621 |
| 2622 /** | 2622 /** |
| 2623 * This verifies that the given default formal parameter is not part of a func
tion typed | 2623 * This verifies that the given default formal parameter is not part of a func
tion typed |
| 2624 * parameter. | 2624 * parameter. |
| 2625 * | 2625 * |
| 2626 * @param node the default formal parameter to evaluate | 2626 * @param node the default formal parameter to evaluate |
| 2627 * @return `true` if and only if an error code is generated on the passed node | 2627 * @return `true` if and only if an error code is generated on the passed node |
| 2628 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]. | 2628 * See [CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNCTION_TYPED_PARAMETER]. |
| 2629 */ | 2629 */ |
| 2630 bool _checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node
) { | 2630 bool _checkForDefaultValueInFunctionTypedParameter(DefaultFormalParameter node
) { |
| 2631 // OK, not in a function typed parameter. | 2631 // OK, not in a function typed parameter. |
| 2632 if (!_isInFunctionTypedFormalParameter) { | 2632 if (!_isInFunctionTypedFormalParameter) { |
| 2633 return false; | 2633 return false; |
| 2634 } | 2634 } |
| 2635 // OK, no default value. | 2635 // OK, no default value. |
| 2636 if (node.defaultValue == null) { | 2636 if (node.defaultValue == null) { |
| 2637 return false; | 2637 return false; |
| 2638 } | 2638 } |
| 2639 // Report problem. | 2639 // Report problem. |
| 2640 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPED_PARAMETER, node, []); | 2640 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_IN_FUNC
TION_TYPED_PARAMETER, node); |
| 2641 return true; | 2641 return true; |
| 2642 } | 2642 } |
| 2643 | 2643 |
| 2644 /** | 2644 /** |
| 2645 * This verifies that any deferred imports in the given compilation unit have
a unique prefix. | 2645 * This verifies that any deferred imports in the given compilation unit have
a unique prefix. |
| 2646 * | 2646 * |
| 2647 * @param node the compilation unit containing the imports to be checked | 2647 * @param node the compilation unit containing the imports to be checked |
| 2648 * @return `true` if an error was generated | 2648 * @return `true` if an error was generated |
| 2649 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]. | 2649 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]. |
| 2650 */ | 2650 */ |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3026 /** | 3026 /** |
| 3027 * This verifies that the passed field formal parameter is in a constructor de
claration. | 3027 * This verifies that the passed field formal parameter is in a constructor de
claration. |
| 3028 * | 3028 * |
| 3029 * @param node the field formal parameter to test | 3029 * @param node the field formal parameter to test |
| 3030 * @return `true` if and only if an error code is generated on the passed node | 3030 * @return `true` if and only if an error code is generated on the passed node |
| 3031 * See [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]. | 3031 * See [CompileTimeErrorCode.FIELD_INITIALIZER_OUTSIDE_CONSTRUCTOR]. |
| 3032 */ | 3032 */ |
| 3033 bool _checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamet
er node) { | 3033 bool _checkForFieldInitializingFormalRedirectingConstructor(FieldFormalParamet
er node) { |
| 3034 ConstructorDeclaration constructor = node.getAncestor((node) => node is Cons
tructorDeclaration); | 3034 ConstructorDeclaration constructor = node.getAncestor((node) => node is Cons
tructorDeclaration); |
| 3035 if (constructor == null) { | 3035 if (constructor == null) { |
| 3036 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_O
UTSIDE_CONSTRUCTOR, node, []); | 3036 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_O
UTSIDE_CONSTRUCTOR, node); |
| 3037 return true; | 3037 return true; |
| 3038 } | 3038 } |
| 3039 // constructor cannot be a factory | 3039 // constructor cannot be a factory |
| 3040 if (constructor.factoryKeyword != null) { | 3040 if (constructor.factoryKeyword != null) { |
| 3041 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_F
ACTORY_CONSTRUCTOR, node, []); | 3041 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER_F
ACTORY_CONSTRUCTOR, node); |
| 3042 return true; | 3042 return true; |
| 3043 } | 3043 } |
| 3044 // constructor cannot have a redirection | 3044 // constructor cannot have a redirection |
| 3045 for (ConstructorInitializer initializer in constructor.initializers) { | 3045 for (ConstructorInitializer initializer in constructor.initializers) { |
| 3046 if (initializer is RedirectingConstructorInvocation) { | 3046 if (initializer is RedirectingConstructorInvocation) { |
| 3047 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER
_REDIRECTING_CONSTRUCTOR, node, []); | 3047 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZER
_REDIRECTING_CONSTRUCTOR, node); |
| 3048 return true; | 3048 return true; |
| 3049 } | 3049 } |
| 3050 } | 3050 } |
| 3051 // OK | 3051 // OK |
| 3052 return false; | 3052 return false; |
| 3053 } | 3053 } |
| 3054 | 3054 |
| 3055 /** | 3055 /** |
| 3056 * This verifies that the passed variable declaration list has only initialize
d variables if the | 3056 * This verifies that the passed variable declaration list has only initialize
d variables if the |
| 3057 * list is final or const. This method is called by | 3057 * list is final or const. This method is called by |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3206 } | 3206 } |
| 3207 } | 3207 } |
| 3208 if (parent is PrefixedIdentifier) { | 3208 if (parent is PrefixedIdentifier) { |
| 3209 PrefixedIdentifier prefixed = parent; | 3209 PrefixedIdentifier prefixed = parent; |
| 3210 if (identical(prefixed.identifier, node)) { | 3210 if (identical(prefixed.identifier, node)) { |
| 3211 return false; | 3211 return false; |
| 3212 } | 3212 } |
| 3213 } | 3213 } |
| 3214 // report problem | 3214 // report problem |
| 3215 if (_isInStaticMethod) { | 3215 if (_isInStaticMethod) { |
| 3216 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANCE_MEMBER_ACC
ESS_FROM_STATIC, node, []); | 3216 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANCE_MEMBER_ACC
ESS_FROM_STATIC, node); |
| 3217 } else if (_isInFactory) { | 3217 } else if (_isInFactory) { |
| 3218 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANCE_MEMBER_ACC
ESS_FROM_FACTORY, node, []); | 3218 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INSTANCE_MEMBER_ACC
ESS_FROM_FACTORY, node); |
| 3219 } else { | 3219 } else { |
| 3220 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPLICIT_THIS_REFER
ENCE_IN_INITIALIZER, node, []); | 3220 _errorReporter.reportErrorForNode(CompileTimeErrorCode.IMPLICIT_THIS_REFER
ENCE_IN_INITIALIZER, node); |
| 3221 } | 3221 } |
| 3222 return true; | 3222 return true; |
| 3223 } | 3223 } |
| 3224 | 3224 |
| 3225 /** | 3225 /** |
| 3226 * This verifies the passed import has unique name among other imported librar
ies. | 3226 * This verifies the passed import has unique name among other imported librar
ies. |
| 3227 * | 3227 * |
| 3228 * @param node the import directive to evaluate | 3228 * @param node the import directive to evaluate |
| 3229 * @param importElement the [ImportElement] retrieved from the node, if the el
ement in the | 3229 * @param importElement the [ImportElement] retrieved from the node, if the el
ement in the |
| 3230 * node was `null`, then this method is not called | 3230 * node was `null`, then this method is not called |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3440 * This verifies that the passed [Annotation] isn't defined in a deferred libr
ary. | 3440 * This verifies that the passed [Annotation] isn't defined in a deferred libr
ary. |
| 3441 * | 3441 * |
| 3442 * @param node the [Annotation] | 3442 * @param node the [Annotation] |
| 3443 * @return `true` if and only if an error code is generated on the passed node | 3443 * @return `true` if and only if an error code is generated on the passed node |
| 3444 * See [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY]. | 3444 * See [CompileTimeErrorCode.INVALID_ANNOTATION_FROM_DEFERRED_LIBRARY]. |
| 3445 */ | 3445 */ |
| 3446 bool _checkForInvalidAnnotationFromDeferredLibrary(Annotation node) { | 3446 bool _checkForInvalidAnnotationFromDeferredLibrary(Annotation node) { |
| 3447 Identifier nameIdentifier = node.name; | 3447 Identifier nameIdentifier = node.name; |
| 3448 if (nameIdentifier is PrefixedIdentifier) { | 3448 if (nameIdentifier is PrefixedIdentifier) { |
| 3449 if (nameIdentifier.isDeferred) { | 3449 if (nameIdentifier.isDeferred) { |
| 3450 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATIO
N_FROM_DEFERRED_LIBRARY, node.name, []); | 3450 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_ANNOTATIO
N_FROM_DEFERRED_LIBRARY, node.name); |
| 3451 return true; | 3451 return true; |
| 3452 } | 3452 } |
| 3453 } | 3453 } |
| 3454 return false; | 3454 return false; |
| 3455 } | 3455 } |
| 3456 | 3456 |
| 3457 /** | 3457 /** |
| 3458 * This verifies that the passed left hand side and right hand side represent
a valid assignment. | 3458 * This verifies that the passed left hand side and right hand side represent
a valid assignment. |
| 3459 * | 3459 * |
| 3460 * @param lhs the left hand side expression | 3460 * @param lhs the left hand side expression |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3548 | 3548 |
| 3549 /** | 3549 /** |
| 3550 * This verifies that the usage of the passed 'this' is valid. | 3550 * This verifies that the usage of the passed 'this' is valid. |
| 3551 * | 3551 * |
| 3552 * @param node the 'this' expression to evaluate | 3552 * @param node the 'this' expression to evaluate |
| 3553 * @return `true` if and only if an error code is generated on the passed node | 3553 * @return `true` if and only if an error code is generated on the passed node |
| 3554 * See [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]. | 3554 * See [CompileTimeErrorCode.INVALID_REFERENCE_TO_THIS]. |
| 3555 */ | 3555 */ |
| 3556 bool _checkForInvalidReferenceToThis(ThisExpression node) { | 3556 bool _checkForInvalidReferenceToThis(ThisExpression node) { |
| 3557 if (!_isThisInValidContext(node)) { | 3557 if (!_isThisInValidContext(node)) { |
| 3558 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_REFERENCE_T
O_THIS, node, []); | 3558 _errorReporter.reportErrorForNode(CompileTimeErrorCode.INVALID_REFERENCE_T
O_THIS, node); |
| 3559 return true; | 3559 return true; |
| 3560 } | 3560 } |
| 3561 return false; | 3561 return false; |
| 3562 } | 3562 } |
| 3563 | 3563 |
| 3564 /** | 3564 /** |
| 3565 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav
e a type | 3565 * Checks to ensure that the passed [ListLiteral] or [MapLiteral] does not hav
e a type |
| 3566 * parameter as a type argument. | 3566 * parameter as a type argument. |
| 3567 * | 3567 * |
| 3568 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective | 3568 * @param arguments a non-`null`, non-empty [TypeName] node list from the resp
ective |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3691 return false; | 3691 return false; |
| 3692 } | 3692 } |
| 3693 String className = _enclosingClass.name; | 3693 String className = _enclosingClass.name; |
| 3694 if (className == null) { | 3694 if (className == null) { |
| 3695 return false; | 3695 return false; |
| 3696 } | 3696 } |
| 3697 bool problemReported = false; | 3697 bool problemReported = false; |
| 3698 // check accessors | 3698 // check accessors |
| 3699 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { | 3699 for (PropertyAccessorElement accessor in _enclosingClass.accessors) { |
| 3700 if (className == accessor.name) { | 3700 if (className == accessor.name) { |
| 3701 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.MEMBER_WITH_CLA
SS_NAME, accessor.nameOffset, className.length, []); | 3701 _errorReporter.reportErrorForOffset(CompileTimeErrorCode.MEMBER_WITH_CLA
SS_NAME, accessor.nameOffset, className.length); |
| 3702 problemReported = true; | 3702 problemReported = true; |
| 3703 } | 3703 } |
| 3704 } | 3704 } |
| 3705 // don't check methods, they would be constructors | 3705 // don't check methods, they would be constructors |
| 3706 // done | 3706 // done |
| 3707 return problemReported; | 3707 return problemReported; |
| 3708 } | 3708 } |
| 3709 | 3709 |
| 3710 /** | 3710 /** |
| 3711 * Check to make sure that all similarly typed accessors are of the same type
(including inherited | 3711 * Check to make sure that all similarly typed accessors are of the same type
(including inherited |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3847 * See [StaticWarningCode.MIXED_RETURN_TYPES]. | 3847 * See [StaticWarningCode.MIXED_RETURN_TYPES]. |
| 3848 */ | 3848 */ |
| 3849 bool _checkForMixedReturns(BlockFunctionBody node) { | 3849 bool _checkForMixedReturns(BlockFunctionBody node) { |
| 3850 if (_hasReturnWithoutValue) { | 3850 if (_hasReturnWithoutValue) { |
| 3851 return false; | 3851 return false; |
| 3852 } | 3852 } |
| 3853 int withCount = _returnsWith.length; | 3853 int withCount = _returnsWith.length; |
| 3854 int withoutCount = _returnsWithout.length; | 3854 int withoutCount = _returnsWithout.length; |
| 3855 if (withCount > 0 && withoutCount > 0) { | 3855 if (withCount > 0 && withoutCount > 0) { |
| 3856 for (int i = 0; i < withCount; i++) { | 3856 for (int i = 0; i < withCount; i++) { |
| 3857 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES,
_returnsWith[i].keyword, []); | 3857 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES,
_returnsWith[i].keyword); |
| 3858 } | 3858 } |
| 3859 for (int i = 0; i < withoutCount; i++) { | 3859 for (int i = 0; i < withoutCount; i++) { |
| 3860 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES,
_returnsWithout[i].keyword, []); | 3860 _errorReporter.reportErrorForToken(StaticWarningCode.MIXED_RETURN_TYPES,
_returnsWithout[i].keyword); |
| 3861 } | 3861 } |
| 3862 return true; | 3862 return true; |
| 3863 } | 3863 } |
| 3864 return false; | 3864 return false; |
| 3865 } | 3865 } |
| 3866 | 3866 |
| 3867 /** | 3867 /** |
| 3868 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. | 3868 * This verifies that the passed mixin does not have an explicitly declared co
nstructor. |
| 3869 * | 3869 * |
| 3870 * @param mixinName the node to report problem on | 3870 * @param mixinName the node to report problem on |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3922 * @param node the constructor declaration to evaluate | 3922 * @param node the constructor declaration to evaluate |
| 3923 * @return `true` if and only if an error code is generated on the passed node | 3923 * @return `true` if and only if an error code is generated on the passed node |
| 3924 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. | 3924 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. |
| 3925 */ | 3925 */ |
| 3926 bool _checkForMultipleSuperInitializers(ConstructorDeclaration node) { | 3926 bool _checkForMultipleSuperInitializers(ConstructorDeclaration node) { |
| 3927 int numSuperInitializers = 0; | 3927 int numSuperInitializers = 0; |
| 3928 for (ConstructorInitializer initializer in node.initializers) { | 3928 for (ConstructorInitializer initializer in node.initializers) { |
| 3929 if (initializer is SuperConstructorInvocation) { | 3929 if (initializer is SuperConstructorInvocation) { |
| 3930 numSuperInitializers++; | 3930 numSuperInitializers++; |
| 3931 if (numSuperInitializers > 1) { | 3931 if (numSuperInitializers > 1) { |
| 3932 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_SUPER_
INITIALIZERS, initializer, []); | 3932 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_SUPER_
INITIALIZERS, initializer); |
| 3933 } | 3933 } |
| 3934 } | 3934 } |
| 3935 } | 3935 } |
| 3936 return numSuperInitializers > 0; | 3936 return numSuperInitializers > 0; |
| 3937 } | 3937 } |
| 3938 | 3938 |
| 3939 /** | 3939 /** |
| 3940 * Checks to ensure that native function bodies can only in SDK code. | 3940 * Checks to ensure that native function bodies can only in SDK code. |
| 3941 * | 3941 * |
| 3942 * @param node the native function body to test | 3942 * @param node the native function body to test |
| 3943 * @return `true` if and only if an error code is generated on the passed node | 3943 * @return `true` if and only if an error code is generated on the passed node |
| 3944 * See [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]. | 3944 * See [ParserErrorCode.NATIVE_FUNCTION_BODY_IN_NON_SDK_CODE]. |
| 3945 */ | 3945 */ |
| 3946 bool _checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { | 3946 bool _checkForNativeFunctionBodyInNonSDKCode(NativeFunctionBody node) { |
| 3947 if (!_isInSystemLibrary && !_hasExtUri) { | 3947 if (!_isInSystemLibrary && !_hasExtUri) { |
| 3948 _errorReporter.reportErrorForNode(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_
NON_SDK_CODE, node, []); | 3948 _errorReporter.reportErrorForNode(ParserErrorCode.NATIVE_FUNCTION_BODY_IN_
NON_SDK_CODE, node); |
| 3949 return true; | 3949 return true; |
| 3950 } | 3950 } |
| 3951 return false; | 3951 return false; |
| 3952 } | 3952 } |
| 3953 | 3953 |
| 3954 /** | 3954 /** |
| 3955 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. | 3955 * This verifies that the passed 'new' instance creation expression invokes ex
isting constructor. |
| 3956 * | 3956 * |
| 3957 * This method assumes that the instance creation was tested to be 'new' befor
e being called. | 3957 * This method assumes that the instance creation was tested to be 'new' befor
e being called. |
| 3958 * | 3958 * |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4170 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is | 4170 * Checks to ensure that the expressions that need to be of type bool, are. Ot
herwise an error is |
| 4171 * reported on the expression. | 4171 * reported on the expression. |
| 4172 * | 4172 * |
| 4173 * @param condition the conditional expression to test | 4173 * @param condition the conditional expression to test |
| 4174 * @return `true` if and only if an error code is generated on the passed node | 4174 * @return `true` if and only if an error code is generated on the passed node |
| 4175 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. | 4175 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. |
| 4176 */ | 4176 */ |
| 4177 bool _checkForNonBoolCondition(Expression condition) { | 4177 bool _checkForNonBoolCondition(Expression condition) { |
| 4178 DartType conditionType = getStaticType(condition); | 4178 DartType conditionType = getStaticType(condition); |
| 4179 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4179 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { |
| 4180 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_CONDITION
, condition, []); | 4180 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_CONDITION
, condition); |
| 4181 return true; | 4181 return true; |
| 4182 } | 4182 } |
| 4183 return false; | 4183 return false; |
| 4184 } | 4184 } |
| 4185 | 4185 |
| 4186 /** | 4186 /** |
| 4187 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. | 4187 * This verifies that the passed assert statement has either a 'bool' or '() -
> bool' input. |
| 4188 * | 4188 * |
| 4189 * @param node the assert statement to evaluate | 4189 * @param node the assert statement to evaluate |
| 4190 * @return `true` if and only if an error code is generated on the passed node | 4190 * @return `true` if and only if an error code is generated on the passed node |
| 4191 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. | 4191 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. |
| 4192 */ | 4192 */ |
| 4193 bool _checkForNonBoolExpression(AssertStatement node) { | 4193 bool _checkForNonBoolExpression(AssertStatement node) { |
| 4194 Expression expression = node.condition; | 4194 Expression expression = node.condition; |
| 4195 DartType type = getStaticType(expression); | 4195 DartType type = getStaticType(expression); |
| 4196 if (type is InterfaceType) { | 4196 if (type is InterfaceType) { |
| 4197 if (!type.isAssignableTo(_boolType)) { | 4197 if (!type.isAssignableTo(_boolType)) { |
| 4198 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS
ION, expression, []); | 4198 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS
ION, expression); |
| 4199 return true; | 4199 return true; |
| 4200 } | 4200 } |
| 4201 } else if (type is FunctionType) { | 4201 } else if (type is FunctionType) { |
| 4202 FunctionType functionType = type; | 4202 FunctionType functionType = type; |
| 4203 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_boolType)) { | 4203 if (functionType.typeArguments.length == 0 && !functionType.returnType.isA
ssignableTo(_boolType)) { |
| 4204 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS
ION, expression, []); | 4204 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_EXPRESS
ION, expression); |
| 4205 return true; | 4205 return true; |
| 4206 } | 4206 } |
| 4207 } | 4207 } |
| 4208 return false; | 4208 return false; |
| 4209 } | 4209 } |
| 4210 | 4210 |
| 4211 /** | 4211 /** |
| 4212 * Checks to ensure that the given expression is assignable to bool. | 4212 * Checks to ensure that the given expression is assignable to bool. |
| 4213 * | 4213 * |
| 4214 * @param expression the expression expression to test | 4214 * @param expression the expression expression to test |
| 4215 * @return `true` if and only if an error code is generated on the passed node | 4215 * @return `true` if and only if an error code is generated on the passed node |
| 4216 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. | 4216 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. |
| 4217 */ | 4217 */ |
| 4218 bool _checkForNonBoolNegationExpression(Expression expression) { | 4218 bool _checkForNonBoolNegationExpression(Expression expression) { |
| 4219 DartType conditionType = getStaticType(expression); | 4219 DartType conditionType = getStaticType(expression); |
| 4220 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4220 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { |
| 4221 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_NEGATION_
EXPRESSION, expression, []); | 4221 _errorReporter.reportErrorForNode(StaticTypeWarningCode.NON_BOOL_NEGATION_
EXPRESSION, expression); |
| 4222 return true; | 4222 return true; |
| 4223 } | 4223 } |
| 4224 return false; | 4224 return false; |
| 4225 } | 4225 } |
| 4226 | 4226 |
| 4227 /** | 4227 /** |
| 4228 * This verifies the passed map literal either: | 4228 * This verifies the passed map literal either: |
| 4229 * * has `const modifier` | 4229 * * has `const modifier` |
| 4230 * * has explicit type arguments | 4230 * * has explicit type arguments |
| 4231 * * is not start of the statement | 4231 * * is not start of the statement |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4246 // prepare statement | 4246 // prepare statement |
| 4247 Statement statement = node.getAncestor((node) => node is ExpressionStatement
); | 4247 Statement statement = node.getAncestor((node) => node is ExpressionStatement
); |
| 4248 if (statement == null) { | 4248 if (statement == null) { |
| 4249 return false; | 4249 return false; |
| 4250 } | 4250 } |
| 4251 // OK, statement does not start with map | 4251 // OK, statement does not start with map |
| 4252 if (!identical(statement.beginToken, node.beginToken)) { | 4252 if (!identical(statement.beginToken, node.beginToken)) { |
| 4253 return false; | 4253 return false; |
| 4254 } | 4254 } |
| 4255 // report problem | 4255 // report problem |
| 4256 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPR
ESSION_STATEMENT, node, []); | 4256 _errorReporter.reportErrorForNode(CompileTimeErrorCode.NON_CONST_MAP_AS_EXPR
ESSION_STATEMENT, node); |
| 4257 return true; | 4257 return true; |
| 4258 } | 4258 } |
| 4259 | 4259 |
| 4260 /** | 4260 /** |
| 4261 * This verifies the passed method declaration of operator `[]=`, has `void` r
eturn | 4261 * This verifies the passed method declaration of operator `[]=`, has `void` r
eturn |
| 4262 * type. | 4262 * type. |
| 4263 * | 4263 * |
| 4264 * @param node the method declaration to evaluate | 4264 * @param node the method declaration to evaluate |
| 4265 * @return `true` if and only if an error code is generated on the passed node | 4265 * @return `true` if and only if an error code is generated on the passed node |
| 4266 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]. | 4266 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]. |
| 4267 */ | 4267 */ |
| 4268 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { | 4268 bool _checkForNonVoidReturnTypeForOperator(MethodDeclaration node) { |
| 4269 // check that []= operator | 4269 // check that []= operator |
| 4270 SimpleIdentifier name = node.name; | 4270 SimpleIdentifier name = node.name; |
| 4271 if (name.name != "[]=") { | 4271 if (name.name != "[]=") { |
| 4272 return false; | 4272 return false; |
| 4273 } | 4273 } |
| 4274 // check return type | 4274 // check return type |
| 4275 TypeName typeName = node.returnType; | 4275 TypeName typeName = node.returnType; |
| 4276 if (typeName != null) { | 4276 if (typeName != null) { |
| 4277 DartType type = typeName.type; | 4277 DartType type = typeName.type; |
| 4278 if (type != null && !type.isVoid) { | 4278 if (type != null && !type.isVoid) { |
| 4279 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_
OPERATOR, typeName, []); | 4279 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_
OPERATOR, typeName); |
| 4280 } | 4280 } |
| 4281 } | 4281 } |
| 4282 // no warning | 4282 // no warning |
| 4283 return false; | 4283 return false; |
| 4284 } | 4284 } |
| 4285 | 4285 |
| 4286 /** | 4286 /** |
| 4287 * This verifies the passed setter has no return type or the `void` return typ
e. | 4287 * This verifies the passed setter has no return type or the `void` return typ
e. |
| 4288 * | 4288 * |
| 4289 * @param typeName the type name to evaluate | 4289 * @param typeName the type name to evaluate |
| 4290 * @return `true` if and only if an error code is generated on the passed node | 4290 * @return `true` if and only if an error code is generated on the passed node |
| 4291 * See [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]. | 4291 * See [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]. |
| 4292 */ | 4292 */ |
| 4293 bool _checkForNonVoidReturnTypeForSetter(TypeName typeName) { | 4293 bool _checkForNonVoidReturnTypeForSetter(TypeName typeName) { |
| 4294 if (typeName != null) { | 4294 if (typeName != null) { |
| 4295 DartType type = typeName.type; | 4295 DartType type = typeName.type; |
| 4296 if (type != null && !type.isVoid) { | 4296 if (type != null && !type.isVoid) { |
| 4297 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_
SETTER, typeName, []); | 4297 _errorReporter.reportErrorForNode(StaticWarningCode.NON_VOID_RETURN_FOR_
SETTER, typeName); |
| 4298 } | 4298 } |
| 4299 } | 4299 } |
| 4300 return false; | 4300 return false; |
| 4301 } | 4301 } |
| 4302 | 4302 |
| 4303 /** | 4303 /** |
| 4304 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. | 4304 * This verifies the passed operator-method declaration, does not have an opti
onal parameter. |
| 4305 * | 4305 * |
| 4306 * This method assumes that the method declaration was tested to be an operato
r declaration before | 4306 * This method assumes that the method declaration was tested to be an operato
r declaration before |
| 4307 * being called. | 4307 * being called. |
| 4308 * | 4308 * |
| 4309 * @param node the method declaration to evaluate | 4309 * @param node the method declaration to evaluate |
| 4310 * @return `true` if and only if an error code is generated on the passed node | 4310 * @return `true` if and only if an error code is generated on the passed node |
| 4311 * See [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]. | 4311 * See [CompileTimeErrorCode.OPTIONAL_PARAMETER_IN_OPERATOR]. |
| 4312 */ | 4312 */ |
| 4313 bool _checkForOptionalParameterInOperator(MethodDeclaration node) { | 4313 bool _checkForOptionalParameterInOperator(MethodDeclaration node) { |
| 4314 FormalParameterList parameterList = node.parameters; | 4314 FormalParameterList parameterList = node.parameters; |
| 4315 if (parameterList == null) { | 4315 if (parameterList == null) { |
| 4316 return false; | 4316 return false; |
| 4317 } | 4317 } |
| 4318 bool foundError = false; | 4318 bool foundError = false; |
| 4319 NodeList<FormalParameter> formalParameters = parameterList.parameters; | 4319 NodeList<FormalParameter> formalParameters = parameterList.parameters; |
| 4320 for (FormalParameter formalParameter in formalParameters) { | 4320 for (FormalParameter formalParameter in formalParameters) { |
| 4321 if (formalParameter.kind.isOptional) { | 4321 if (formalParameter.kind.isOptional) { |
| 4322 _errorReporter.reportErrorForNode(CompileTimeErrorCode.OPTIONAL_PARAMETE
R_IN_OPERATOR, formalParameter, []); | 4322 _errorReporter.reportErrorForNode(CompileTimeErrorCode.OPTIONAL_PARAMETE
R_IN_OPERATOR, formalParameter); |
| 4323 foundError = true; | 4323 foundError = true; |
| 4324 } | 4324 } |
| 4325 } | 4325 } |
| 4326 return foundError; | 4326 return foundError; |
| 4327 } | 4327 } |
| 4328 | 4328 |
| 4329 /** | 4329 /** |
| 4330 * This checks for named optional parameters that begin with '_'. | 4330 * This checks for named optional parameters that begin with '_'. |
| 4331 * | 4331 * |
| 4332 * @param node the default formal parameter to evaluate | 4332 * @param node the default formal parameter to evaluate |
| 4333 * @return `true` if and only if an error code is generated on the passed node | 4333 * @return `true` if and only if an error code is generated on the passed node |
| 4334 * See [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]. | 4334 * See [CompileTimeErrorCode.PRIVATE_OPTIONAL_PARAMETER]. |
| 4335 */ | 4335 */ |
| 4336 bool _checkForPrivateOptionalParameter(FormalParameter node) { | 4336 bool _checkForPrivateOptionalParameter(FormalParameter node) { |
| 4337 // should be named parameter | 4337 // should be named parameter |
| 4338 if (node.kind != ParameterKind.NAMED) { | 4338 if (node.kind != ParameterKind.NAMED) { |
| 4339 return false; | 4339 return false; |
| 4340 } | 4340 } |
| 4341 // name should start with '_' | 4341 // name should start with '_' |
| 4342 SimpleIdentifier name = node.identifier; | 4342 SimpleIdentifier name = node.identifier; |
| 4343 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) { | 4343 if (name.isSynthetic || !StringUtilities.startsWithChar(name.name, 0x5F)) { |
| 4344 return false; | 4344 return false; |
| 4345 } | 4345 } |
| 4346 // report problem | 4346 // report problem |
| 4347 _errorReporter.reportErrorForNode(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARA
METER, node, []); | 4347 _errorReporter.reportErrorForNode(CompileTimeErrorCode.PRIVATE_OPTIONAL_PARA
METER, node); |
| 4348 return true; | 4348 return true; |
| 4349 } | 4349 } |
| 4350 | 4350 |
| 4351 /** | 4351 /** |
| 4352 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and | 4352 * This checks if the passed constructor declaration is the redirecting genera
tive constructor and |
| 4353 * references itself directly or indirectly. | 4353 * references itself directly or indirectly. |
| 4354 * | 4354 * |
| 4355 * @param node the constructor declaration to evaluate | 4355 * @param node the constructor declaration to evaluate |
| 4356 * @param constructorElement the constructor element | 4356 * @param constructorElement the constructor element |
| 4357 * @return `true` if and only if an error code is generated on the passed node | 4357 * @return `true` if and only if an error code is generated on the passed node |
| 4358 * See [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]. | 4358 * See [CompileTimeErrorCode.RECURSIVE_CONSTRUCTOR_REDIRECT]. |
| 4359 */ | 4359 */ |
| 4360 bool _checkForRecursiveConstructorRedirect(ConstructorDeclaration node, Constr
uctorElement constructorElement) { | 4360 bool _checkForRecursiveConstructorRedirect(ConstructorDeclaration node, Constr
uctorElement constructorElement) { |
| 4361 // we check generative constructor here | 4361 // we check generative constructor here |
| 4362 if (node.factoryKeyword != null) { | 4362 if (node.factoryKeyword != null) { |
| 4363 return false; | 4363 return false; |
| 4364 } | 4364 } |
| 4365 // try to find redirecting constructor invocation and analyzer it for recurs
ion | 4365 // try to find redirecting constructor invocation and analyzer it for recurs
ion |
| 4366 for (ConstructorInitializer initializer in node.initializers) { | 4366 for (ConstructorInitializer initializer in node.initializers) { |
| 4367 if (initializer is RedirectingConstructorInvocation) { | 4367 if (initializer is RedirectingConstructorInvocation) { |
| 4368 // OK if no cycle | 4368 // OK if no cycle |
| 4369 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) { | 4369 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) { |
| 4370 return false; | 4370 return false; |
| 4371 } | 4371 } |
| 4372 // report error | 4372 // report error |
| 4373 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_CONSTRU
CTOR_REDIRECT, initializer, []); | 4373 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_CONSTRU
CTOR_REDIRECT, initializer); |
| 4374 return true; | 4374 return true; |
| 4375 } | 4375 } |
| 4376 } | 4376 } |
| 4377 // OK, no redirecting constructor invocation | 4377 // OK, no redirecting constructor invocation |
| 4378 return false; | 4378 return false; |
| 4379 } | 4379 } |
| 4380 | 4380 |
| 4381 /** | 4381 /** |
| 4382 * This checks if the passed constructor declaration has redirected constructo
r and references | 4382 * This checks if the passed constructor declaration has redirected constructo
r and references |
| 4383 * itself directly or indirectly. | 4383 * itself directly or indirectly. |
| 4384 * | 4384 * |
| 4385 * @param node the constructor declaration to evaluate | 4385 * @param node the constructor declaration to evaluate |
| 4386 * @param constructorElement the constructor element | 4386 * @param constructorElement the constructor element |
| 4387 * @return `true` if and only if an error code is generated on the passed node | 4387 * @return `true` if and only if an error code is generated on the passed node |
| 4388 * See [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]. | 4388 * See [CompileTimeErrorCode.RECURSIVE_FACTORY_REDIRECT]. |
| 4389 */ | 4389 */ |
| 4390 bool _checkForRecursiveFactoryRedirect(ConstructorDeclaration node, Constructo
rElement constructorElement) { | 4390 bool _checkForRecursiveFactoryRedirect(ConstructorDeclaration node, Constructo
rElement constructorElement) { |
| 4391 // prepare redirected constructor | 4391 // prepare redirected constructor |
| 4392 ConstructorName redirectedConstructorNode = node.redirectedConstructor; | 4392 ConstructorName redirectedConstructorNode = node.redirectedConstructor; |
| 4393 if (redirectedConstructorNode == null) { | 4393 if (redirectedConstructorNode == null) { |
| 4394 return false; | 4394 return false; |
| 4395 } | 4395 } |
| 4396 // OK if no cycle | 4396 // OK if no cycle |
| 4397 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) { | 4397 if (!_hasRedirectingFactoryConstructorCycle(constructorElement)) { |
| 4398 return false; | 4398 return false; |
| 4399 } | 4399 } |
| 4400 // report error | 4400 // report error |
| 4401 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_FACTORY_RED
IRECT, redirectedConstructorNode, []); | 4401 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RECURSIVE_FACTORY_RED
IRECT, redirectedConstructorNode); |
| 4402 return true; | 4402 return true; |
| 4403 } | 4403 } |
| 4404 | 4404 |
| 4405 /** | 4405 /** |
| 4406 * This checks the class declaration is not a superinterface to itself. | 4406 * This checks the class declaration is not a superinterface to itself. |
| 4407 * | 4407 * |
| 4408 * @param classElt the class element to test | 4408 * @param classElt the class element to test |
| 4409 * @return `true` if and only if an error code is generated on the passed elem
ent | 4409 * @return `true` if and only if an error code is generated on the passed elem
ent |
| 4410 * See [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE], | 4410 * See [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE], |
| 4411 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS], a
nd | 4411 * [CompileTimeErrorCode.RECURSIVE_INTERFACE_INHERITANCE_BASE_CASE_EXTENDS], a
nd |
| (...skipping 20 matching lines...) Expand all Loading... |
| 4432 */ | 4432 */ |
| 4433 bool _checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { | 4433 bool _checkForRedirectingConstructorErrorCodes(ConstructorDeclaration node) { |
| 4434 bool errorReported = false; | 4434 bool errorReported = false; |
| 4435 // | 4435 // |
| 4436 // Check for default values in the parameters | 4436 // Check for default values in the parameters |
| 4437 // | 4437 // |
| 4438 ConstructorName redirectedConstructor = node.redirectedConstructor; | 4438 ConstructorName redirectedConstructor = node.redirectedConstructor; |
| 4439 if (redirectedConstructor != null) { | 4439 if (redirectedConstructor != null) { |
| 4440 for (FormalParameter parameter in node.parameters.parameters) { | 4440 for (FormalParameter parameter in node.parameters.parameters) { |
| 4441 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul
l) { | 4441 if (parameter is DefaultFormalParameter && parameter.defaultValue != nul
l) { |
| 4442 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I
N_REDIRECTING_FACTORY_CONSTRUCTOR, parameter.identifier, []); | 4442 _errorReporter.reportErrorForNode(CompileTimeErrorCode.DEFAULT_VALUE_I
N_REDIRECTING_FACTORY_CONSTRUCTOR, parameter.identifier); |
| 4443 errorReported = true; | 4443 errorReported = true; |
| 4444 } | 4444 } |
| 4445 } | 4445 } |
| 4446 } | 4446 } |
| 4447 // check if there are redirected invocations | 4447 // check if there are redirected invocations |
| 4448 int numRedirections = 0; | 4448 int numRedirections = 0; |
| 4449 for (ConstructorInitializer initializer in node.initializers) { | 4449 for (ConstructorInitializer initializer in node.initializers) { |
| 4450 if (initializer is RedirectingConstructorInvocation) { | 4450 if (initializer is RedirectingConstructorInvocation) { |
| 4451 if (numRedirections > 0) { | 4451 if (numRedirections > 0) { |
| 4452 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_REDIRE
CTING_CONSTRUCTOR_INVOCATIONS, initializer, []); | 4452 _errorReporter.reportErrorForNode(CompileTimeErrorCode.MULTIPLE_REDIRE
CTING_CONSTRUCTOR_INVOCATIONS, initializer); |
| 4453 errorReported = true; | 4453 errorReported = true; |
| 4454 } | 4454 } |
| 4455 if (node.factoryKeyword == null) { | 4455 if (node.factoryKeyword == null) { |
| 4456 RedirectingConstructorInvocation invocation = initializer; | 4456 RedirectingConstructorInvocation invocation = initializer; |
| 4457 ConstructorElement redirectingElement = invocation.staticElement; | 4457 ConstructorElement redirectingElement = invocation.staticElement; |
| 4458 if (redirectingElement == null) { | 4458 if (redirectingElement == null) { |
| 4459 String enclosingTypeName = _enclosingClass.displayName; | 4459 String enclosingTypeName = _enclosingClass.displayName; |
| 4460 String constructorStrName = enclosingTypeName; | 4460 String constructorStrName = enclosingTypeName; |
| 4461 if (invocation.constructorName != null) { | 4461 if (invocation.constructorName != null) { |
| 4462 constructorStrName += ".${invocation.constructorName.name}"; | 4462 constructorStrName += ".${invocation.constructorName.name}"; |
| 4463 } | 4463 } |
| 4464 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_GENE
RATIVE_TO_MISSING_CONSTRUCTOR, invocation, [constructorStrName, enclosingTypeNam
e]); | 4464 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_GENE
RATIVE_TO_MISSING_CONSTRUCTOR, invocation, [constructorStrName, enclosingTypeNam
e]); |
| 4465 } else { | 4465 } else { |
| 4466 if (redirectingElement.isFactory) { | 4466 if (redirectingElement.isFactory) { |
| 4467 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_GE
NERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR, initializer, []); | 4467 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_GE
NERATIVE_TO_NON_GENERATIVE_CONSTRUCTOR, initializer); |
| 4468 } | 4468 } |
| 4469 } | 4469 } |
| 4470 } | 4470 } |
| 4471 numRedirections++; | 4471 numRedirections++; |
| 4472 } | 4472 } |
| 4473 } | 4473 } |
| 4474 // check for other initializers | 4474 // check for other initializers |
| 4475 if (numRedirections > 0) { | 4475 if (numRedirections > 0) { |
| 4476 for (ConstructorInitializer initializer in node.initializers) { | 4476 for (ConstructorInitializer initializer in node.initializers) { |
| 4477 if (initializer is SuperConstructorInvocation) { | 4477 if (initializer is SuperConstructorInvocation) { |
| 4478 _errorReporter.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_REDIRE
CTING_CONSTRUCTOR, initializer, []); | 4478 _errorReporter.reportErrorForNode(CompileTimeErrorCode.SUPER_IN_REDIRE
CTING_CONSTRUCTOR, initializer); |
| 4479 errorReported = true; | 4479 errorReported = true; |
| 4480 } | 4480 } |
| 4481 if (initializer is ConstructorFieldInitializer) { | 4481 if (initializer is ConstructorFieldInitializer) { |
| 4482 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZ
ER_REDIRECTING_CONSTRUCTOR, initializer, []); | 4482 _errorReporter.reportErrorForNode(CompileTimeErrorCode.FIELD_INITIALIZ
ER_REDIRECTING_CONSTRUCTOR, initializer); |
| 4483 errorReported = true; | 4483 errorReported = true; |
| 4484 } | 4484 } |
| 4485 } | 4485 } |
| 4486 } | 4486 } |
| 4487 // done | 4487 // done |
| 4488 return errorReported; | 4488 return errorReported; |
| 4489 } | 4489 } |
| 4490 | 4490 |
| 4491 /** | 4491 /** |
| 4492 * This checks if the passed constructor declaration has redirected constructo
r and references | 4492 * This checks if the passed constructor declaration has redirected constructo
r and references |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4514 // prepare redirected constructor | 4514 // prepare redirected constructor |
| 4515 ConstructorElement redirectedConstructor = constructorElement.redirectedCons
tructor; | 4515 ConstructorElement redirectedConstructor = constructorElement.redirectedCons
tructor; |
| 4516 if (redirectedConstructor == null) { | 4516 if (redirectedConstructor == null) { |
| 4517 return false; | 4517 return false; |
| 4518 } | 4518 } |
| 4519 // OK, it is also 'const' | 4519 // OK, it is also 'const' |
| 4520 if (redirectedConstructor.isConst) { | 4520 if (redirectedConstructor.isConst) { |
| 4521 return false; | 4521 return false; |
| 4522 } | 4522 } |
| 4523 // report error | 4523 // report error |
| 4524 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_TO_NON_CONST
_CONSTRUCTOR, redirectedConstructorNode, []); | 4524 _errorReporter.reportErrorForNode(CompileTimeErrorCode.REDIRECT_TO_NON_CONST
_CONSTRUCTOR, redirectedConstructorNode); |
| 4525 return true; | 4525 return true; |
| 4526 } | 4526 } |
| 4527 | 4527 |
| 4528 /** | 4528 /** |
| 4529 * This checks that the rethrow is inside of a catch clause. | 4529 * This checks that the rethrow is inside of a catch clause. |
| 4530 * | 4530 * |
| 4531 * @param node the rethrow expression to evaluate | 4531 * @param node the rethrow expression to evaluate |
| 4532 * @return `true` if and only if an error code is generated on the passed node | 4532 * @return `true` if and only if an error code is generated on the passed node |
| 4533 * See [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]. | 4533 * See [CompileTimeErrorCode.RETHROW_OUTSIDE_CATCH]. |
| 4534 */ | 4534 */ |
| 4535 bool _checkForRethrowOutsideCatch(RethrowExpression node) { | 4535 bool _checkForRethrowOutsideCatch(RethrowExpression node) { |
| 4536 if (!_isInCatchClause) { | 4536 if (!_isInCatchClause) { |
| 4537 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETHROW_OUTSIDE_CAT
CH, node, []); | 4537 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETHROW_OUTSIDE_CAT
CH, node); |
| 4538 return true; | 4538 return true; |
| 4539 } | 4539 } |
| 4540 return false; | 4540 return false; |
| 4541 } | 4541 } |
| 4542 | 4542 |
| 4543 /** | 4543 /** |
| 4544 * This checks that if the the given constructor declaration is generative, th
en it does not have | 4544 * This checks that if the the given constructor declaration is generative, th
en it does not have |
| 4545 * an expression function body. | 4545 * an expression function body. |
| 4546 * | 4546 * |
| 4547 * @param node the constructor to evaluate | 4547 * @param node the constructor to evaluate |
| 4548 * @return `true` if and only if an error code is generated on the passed node | 4548 * @return `true` if and only if an error code is generated on the passed node |
| 4549 * See [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]. | 4549 * See [CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR]. |
| 4550 */ | 4550 */ |
| 4551 bool _checkForReturnInGenerativeConstructor(ConstructorDeclaration node) { | 4551 bool _checkForReturnInGenerativeConstructor(ConstructorDeclaration node) { |
| 4552 // ignore factory | 4552 // ignore factory |
| 4553 if (node.factoryKeyword != null) { | 4553 if (node.factoryKeyword != null) { |
| 4554 return false; | 4554 return false; |
| 4555 } | 4555 } |
| 4556 // block body (with possible return statement) is checked elsewhere | 4556 // block body (with possible return statement) is checked elsewhere |
| 4557 FunctionBody body = node.body; | 4557 FunctionBody body = node.body; |
| 4558 if (body is! ExpressionFunctionBody) { | 4558 if (body is! ExpressionFunctionBody) { |
| 4559 return false; | 4559 return false; |
| 4560 } | 4560 } |
| 4561 // report error | 4561 // report error |
| 4562 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIVE_
CONSTRUCTOR, body, []); | 4562 _errorReporter.reportErrorForNode(CompileTimeErrorCode.RETURN_IN_GENERATIVE_
CONSTRUCTOR, body); |
| 4563 return true; | 4563 return true; |
| 4564 } | 4564 } |
| 4565 | 4565 |
| 4566 /** | 4566 /** |
| 4567 * This checks that a type mis-match between the return type and the expressed
return type by the | 4567 * This checks that a type mis-match between the return type and the expressed
return type by the |
| 4568 * enclosing method or function. | 4568 * enclosing method or function. |
| 4569 * | 4569 * |
| 4570 * This method is called both by [checkForAllReturnStatementErrorCodes] | 4570 * This method is called both by [checkForAllReturnStatementErrorCodes] |
| 4571 * and [visitExpressionFunctionBody]. | 4571 * and [visitExpressionFunctionBody]. |
| 4572 * | 4572 * |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4701 * | 4701 * |
| 4702 * @param node the function type alias to evaluate | 4702 * @param node the function type alias to evaluate |
| 4703 * @return `true` if and only if an error code is generated on the passed node | 4703 * @return `true` if and only if an error code is generated on the passed node |
| 4704 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. | 4704 * See [CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF]. |
| 4705 */ | 4705 */ |
| 4706 bool _checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node)
{ | 4706 bool _checkForTypeAliasCannotReferenceItself_function(FunctionTypeAlias node)
{ |
| 4707 FunctionTypeAliasElement element = node.element; | 4707 FunctionTypeAliasElement element = node.element; |
| 4708 if (!_hasTypedefSelfReference(element)) { | 4708 if (!_hasTypedefSelfReference(element)) { |
| 4709 return false; | 4709 return false; |
| 4710 } | 4710 } |
| 4711 _errorReporter.reportErrorForNode(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REF
ERENCE_ITSELF, node, []); | 4711 _errorReporter.reportErrorForNode(CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REF
ERENCE_ITSELF, node); |
| 4712 return true; | 4712 return true; |
| 4713 } | 4713 } |
| 4714 | 4714 |
| 4715 /** | 4715 /** |
| 4716 * This verifies that the passed type name is not a deferred type. | 4716 * This verifies that the passed type name is not a deferred type. |
| 4717 * | 4717 * |
| 4718 * @param expression the expression to evaluate | 4718 * @param expression the expression to evaluate |
| 4719 * @return `true` if and only if an error code is generated on the passed node | 4719 * @return `true` if and only if an error code is generated on the passed node |
| 4720 * See [StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]. | 4720 * See [StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]. |
| 4721 */ | 4721 */ |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4784 * member. | 4784 * member. |
| 4785 * | 4785 * |
| 4786 * @param node the type name to evaluate | 4786 * @param node the type name to evaluate |
| 4787 * @return `true` if and only if an error code is generated on the passed node | 4787 * @return `true` if and only if an error code is generated on the passed node |
| 4788 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]. | 4788 * See [StaticWarningCode.TYPE_PARAMETER_REFERENCED_BY_STATIC]. |
| 4789 */ | 4789 */ |
| 4790 bool _checkForTypeParameterReferencedByStatic(TypeName node) { | 4790 bool _checkForTypeParameterReferencedByStatic(TypeName node) { |
| 4791 if (_isInStaticMethod || _isInStaticVariableDeclaration) { | 4791 if (_isInStaticMethod || _isInStaticVariableDeclaration) { |
| 4792 DartType type = node.type; | 4792 DartType type = node.type; |
| 4793 if (type is TypeParameterType) { | 4793 if (type is TypeParameterType) { |
| 4794 _errorReporter.reportErrorForNode(StaticWarningCode.TYPE_PARAMETER_REFER
ENCED_BY_STATIC, node, []); | 4794 _errorReporter.reportErrorForNode(StaticWarningCode.TYPE_PARAMETER_REFER
ENCED_BY_STATIC, node); |
| 4795 return true; | 4795 return true; |
| 4796 } | 4796 } |
| 4797 } | 4797 } |
| 4798 return false; | 4798 return false; |
| 4799 } | 4799 } |
| 4800 | 4800 |
| 4801 /** | 4801 /** |
| 4802 * This checks that if the passed type parameter is a supertype of its bound. | 4802 * This checks that if the passed type parameter is a supertype of its bound. |
| 4803 * | 4803 * |
| 4804 * @param node the type parameter to evaluate | 4804 * @param node the type parameter to evaluate |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4948 * | 4948 * |
| 4949 * @param node the method declaration to evaluate | 4949 * @param node the method declaration to evaluate |
| 4950 * @return `true` if and only if an error code is generated on the passed node | 4950 * @return `true` if and only if an error code is generated on the passed node |
| 4951 * See [StaticWarningCode.VOID_RETURN_FOR_GETTER]. | 4951 * See [StaticWarningCode.VOID_RETURN_FOR_GETTER]. |
| 4952 */ | 4952 */ |
| 4953 bool _checkForVoidReturnType(MethodDeclaration node) { | 4953 bool _checkForVoidReturnType(MethodDeclaration node) { |
| 4954 TypeName returnType = node.returnType; | 4954 TypeName returnType = node.returnType; |
| 4955 if (returnType == null || returnType.name.name != "void") { | 4955 if (returnType == null || returnType.name.name != "void") { |
| 4956 return false; | 4956 return false; |
| 4957 } | 4957 } |
| 4958 _errorReporter.reportErrorForNode(StaticWarningCode.VOID_RETURN_FOR_GETTER,
returnType, []); | 4958 _errorReporter.reportErrorForNode(StaticWarningCode.VOID_RETURN_FOR_GETTER,
returnType); |
| 4959 return true; | 4959 return true; |
| 4960 } | 4960 } |
| 4961 | 4961 |
| 4962 /** | 4962 /** |
| 4963 * This verifies the passed operator-method declaration, has correct number of
parameters. | 4963 * This verifies the passed operator-method declaration, has correct number of
parameters. |
| 4964 * | 4964 * |
| 4965 * This method assumes that the method declaration was tested to be an operato
r declaration before | 4965 * This method assumes that the method declaration was tested to be an operato
r declaration before |
| 4966 * being called. | 4966 * being called. |
| 4967 * | 4967 * |
| 4968 * @param node the method declaration to evaluate | 4968 * @param node the method declaration to evaluate |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5016 */ | 5016 */ |
| 5017 bool _checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, Fo
rmalParameterList parameterList) { | 5017 bool _checkForWrongNumberOfParametersForSetter(SimpleIdentifier setterName, Fo
rmalParameterList parameterList) { |
| 5018 if (setterName == null) { | 5018 if (setterName == null) { |
| 5019 return false; | 5019 return false; |
| 5020 } | 5020 } |
| 5021 if (parameterList == null) { | 5021 if (parameterList == null) { |
| 5022 return false; | 5022 return false; |
| 5023 } | 5023 } |
| 5024 NodeList<FormalParameter> parameters = parameterList.parameters; | 5024 NodeList<FormalParameter> parameters = parameterList.parameters; |
| 5025 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED)
{ | 5025 if (parameters.length != 1 || parameters[0].kind != ParameterKind.REQUIRED)
{ |
| 5026 _errorReporter.reportErrorForNode(CompileTimeErrorCode.WRONG_NUMBER_OF_PAR
AMETERS_FOR_SETTER, setterName, []); | 5026 _errorReporter.reportErrorForNode(CompileTimeErrorCode.WRONG_NUMBER_OF_PAR
AMETERS_FOR_SETTER, setterName); |
| 5027 return true; | 5027 return true; |
| 5028 } | 5028 } |
| 5029 return false; | 5029 return false; |
| 5030 } | 5030 } |
| 5031 | 5031 |
| 5032 /** | 5032 /** |
| 5033 * This verifies that if the given class declaration implements the class Func
tion that it has a | 5033 * This verifies that if the given class declaration implements the class Func
tion that it has a |
| 5034 * concrete implementation of the call method. | 5034 * concrete implementation of the call method. |
| 5035 * | 5035 * |
| 5036 * @return `true` if and only if an error code is generated on the passed node | 5036 * @return `true` if and only if an error code is generated on the passed node |
| 5037 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. | 5037 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. |
| 5038 */ | 5038 */ |
| 5039 bool _checkImplementsFunctionWithoutCall(ClassDeclaration node) { | 5039 bool _checkImplementsFunctionWithoutCall(ClassDeclaration node) { |
| 5040 if (node.isAbstract) { | 5040 if (node.isAbstract) { |
| 5041 return false; | 5041 return false; |
| 5042 } | 5042 } |
| 5043 ClassElement classElement = node.element; | 5043 ClassElement classElement = node.element; |
| 5044 if (classElement == null) { | 5044 if (classElement == null) { |
| 5045 return false; | 5045 return false; |
| 5046 } | 5046 } |
| 5047 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { | 5047 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { |
| 5048 return false; | 5048 return false; |
| 5049 } | 5049 } |
| 5050 // If there is a noSuchMethod method, then don't report the warning, see dar
tbug.com/16078 | 5050 // If there is a noSuchMethod method, then don't report the warning, see dar
tbug.com/16078 |
| 5051 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != nu
ll) { | 5051 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != nu
ll) { |
| 5052 return false; | 5052 return false; |
| 5053 } | 5053 } |
| 5054 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement
, "call"); | 5054 ExecutableElement callMethod = _inheritanceManager.lookupMember(classElement
, "call"); |
| 5055 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met
hodElement).isAbstract) { | 5055 if (callMethod == null || callMethod is! MethodElement || (callMethod as Met
hodElement).isAbstract) { |
| 5056 _errorReporter.reportErrorForNode(StaticWarningCode.FUNCTION_WITHOUT_CALL,
node.name, []); | 5056 _errorReporter.reportErrorForNode(StaticWarningCode.FUNCTION_WITHOUT_CALL,
node.name); |
| 5057 return true; | 5057 return true; |
| 5058 } | 5058 } |
| 5059 return false; | 5059 return false; |
| 5060 } | 5060 } |
| 5061 | 5061 |
| 5062 /** | 5062 /** |
| 5063 * This verifies that the given class declaration does not have the same class
in the 'extends' | 5063 * This verifies that the given class declaration does not have the same class
in the 'extends' |
| 5064 * and 'implements' clauses. | 5064 * and 'implements' clauses. |
| 5065 * | 5065 * |
| 5066 * @return `true` if and only if an error code is generated on the passed node | 5066 * @return `true` if and only if an error code is generated on the passed node |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5167 * @return `true` if an error was generated | 5167 * @return `true` if an error was generated |
| 5168 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]. | 5168 * See [CompileTimeErrorCode.SHARED_DEFERRED_PREFIX]. |
| 5169 */ | 5169 */ |
| 5170 bool _hasDeferredPrefixCollision(List<ImportDirective> directives) { | 5170 bool _hasDeferredPrefixCollision(List<ImportDirective> directives) { |
| 5171 bool foundError = false; | 5171 bool foundError = false; |
| 5172 int count = directives.length; | 5172 int count = directives.length; |
| 5173 if (count > 1) { | 5173 if (count > 1) { |
| 5174 for (int i = 0; i < count; i++) { | 5174 for (int i = 0; i < count; i++) { |
| 5175 sc.Token deferredToken = directives[i].deferredToken; | 5175 sc.Token deferredToken = directives[i].deferredToken; |
| 5176 if (deferredToken != null) { | 5176 if (deferredToken != null) { |
| 5177 _errorReporter.reportErrorForToken(CompileTimeErrorCode.SHARED_DEFERRE
D_PREFIX, deferredToken, []); | 5177 _errorReporter.reportErrorForToken(CompileTimeErrorCode.SHARED_DEFERRE
D_PREFIX, deferredToken); |
| 5178 foundError = true; | 5178 foundError = true; |
| 5179 } | 5179 } |
| 5180 } | 5180 } |
| 5181 } | 5181 } |
| 5182 return foundError; | 5182 return foundError; |
| 5183 } | 5183 } |
| 5184 | 5184 |
| 5185 /** | 5185 /** |
| 5186 * @return `true` if the given constructor redirects to itself, directly or in
directly | 5186 * @return `true` if the given constructor redirects to itself, directly or in
directly |
| 5187 */ | 5187 */ |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5487 toCheck.add(type.element); | 5487 toCheck.add(type.element); |
| 5488 // type arguments | 5488 // type arguments |
| 5489 if (type is InterfaceType) { | 5489 if (type is InterfaceType) { |
| 5490 InterfaceType interfaceType = type; | 5490 InterfaceType interfaceType = type; |
| 5491 for (DartType typeArgument in interfaceType.typeArguments) { | 5491 for (DartType typeArgument in interfaceType.typeArguments) { |
| 5492 _addTypeToCheck(typeArgument); | 5492 _addTypeToCheck(typeArgument); |
| 5493 } | 5493 } |
| 5494 } | 5494 } |
| 5495 } | 5495 } |
| 5496 } | 5496 } |
| OLD | NEW |