| 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 analyzer.src.generated.error_verifier; | 5 library analyzer.src.generated.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 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 return super.visitArgumentList(node); | 340 return super.visitArgumentList(node); |
| 341 } | 341 } |
| 342 | 342 |
| 343 @override | 343 @override |
| 344 Object visitAsExpression(AsExpression node) { | 344 Object visitAsExpression(AsExpression node) { |
| 345 _checkForTypeAnnotationDeferredClass(node.type); | 345 _checkForTypeAnnotationDeferredClass(node.type); |
| 346 return super.visitAsExpression(node); | 346 return super.visitAsExpression(node); |
| 347 } | 347 } |
| 348 | 348 |
| 349 @override | 349 @override |
| 350 Object visitAssertInitializer(AssertInitializer node) { |
| 351 _checkForNonBoolExpression(node); |
| 352 _checkAssertMessage(node); |
| 353 return super.visitAssertInitializer(node); |
| 354 } |
| 355 |
| 356 @override |
| 350 Object visitAssertStatement(AssertStatement node) { | 357 Object visitAssertStatement(AssertStatement node) { |
| 351 _checkForNonBoolExpression(node); | 358 _checkForNonBoolExpression(node); |
| 352 _checkAssertMessage(node); | 359 _checkAssertMessage(node); |
| 353 return super.visitAssertStatement(node); | 360 return super.visitAssertStatement(node); |
| 354 } | 361 } |
| 355 | 362 |
| 356 @override | 363 @override |
| 357 Object visitAssignmentExpression(AssignmentExpression node) { | 364 Object visitAssignmentExpression(AssignmentExpression node) { |
| 358 TokenType operatorType = node.operator.type; | 365 TokenType operatorType = node.operator.type; |
| 359 Expression lhs = node.leftHandSide; | 366 Expression lhs = node.leftHandSide; |
| (...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1288 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; | 1295 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; |
| 1289 } else { | 1296 } else { |
| 1290 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; | 1297 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; |
| 1291 } | 1298 } |
| 1292 _errorReporter.reportErrorForNode(errorCode, node); | 1299 _errorReporter.reportErrorForNode(errorCode, node); |
| 1293 } | 1300 } |
| 1294 return super.visitYieldStatement(node); | 1301 return super.visitYieldStatement(node); |
| 1295 } | 1302 } |
| 1296 | 1303 |
| 1297 /** | 1304 /** |
| 1298 * If the given assert [statement] specifies a message, verify that support | 1305 * If the given [assertion] specifies a message, verify that support |
| 1299 * for assertions with messages is enabled. | 1306 * for assertions with messages is enabled. |
| 1300 */ | 1307 */ |
| 1301 void _checkAssertMessage(AssertStatement statement) { | 1308 void _checkAssertMessage(Assertion assertion) { |
| 1302 Expression expression = statement.message; | 1309 Expression expression = assertion.message; |
| 1303 if (expression != null && !enableAssertMessage) { | 1310 if (expression != null && !enableAssertMessage) { |
| 1304 _errorReporter.reportErrorForNode( | 1311 _errorReporter.reportErrorForNode( |
| 1305 CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT, expression); | 1312 CompileTimeErrorCode.EXTRA_ARGUMENT_TO_ASSERT, expression); |
| 1306 } | 1313 } |
| 1307 } | 1314 } |
| 1308 | 1315 |
| 1309 /** | 1316 /** |
| 1310 * Given a list of [directives] that have the same prefix, generate an error | 1317 * Given a list of [directives] that have the same prefix, generate an error |
| 1311 * if there is more than one import and any of those imports is deferred. | 1318 * if there is more than one import and any of those imports is deferred. |
| 1312 * | 1319 * |
| (...skipping 3843 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5156 void _checkForNonBoolCondition(Expression condition) { | 5163 void _checkForNonBoolCondition(Expression condition) { |
| 5157 DartType conditionType = getStaticType(condition); | 5164 DartType conditionType = getStaticType(condition); |
| 5158 if (conditionType != null && | 5165 if (conditionType != null && |
| 5159 !_typeSystem.isAssignableTo(conditionType, _boolType)) { | 5166 !_typeSystem.isAssignableTo(conditionType, _boolType)) { |
| 5160 _errorReporter.reportErrorForNode( | 5167 _errorReporter.reportErrorForNode( |
| 5161 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); | 5168 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); |
| 5162 } | 5169 } |
| 5163 } | 5170 } |
| 5164 | 5171 |
| 5165 /** | 5172 /** |
| 5166 * Verify that the given assert [statement] has either a 'bool' or | 5173 * Verify that the given [assertion] has either a 'bool' or '() -> bool' |
| 5167 * '() -> bool' input. | 5174 * condition. |
| 5168 * | 5175 * |
| 5169 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. | 5176 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. |
| 5170 */ | 5177 */ |
| 5171 void _checkForNonBoolExpression(AssertStatement statement) { | 5178 void _checkForNonBoolExpression(Assertion assertion) { |
| 5172 Expression expression = statement.condition; | 5179 Expression expression = assertion.condition; |
| 5173 DartType type = getStaticType(expression); | 5180 DartType type = getStaticType(expression); |
| 5174 if (type is InterfaceType) { | 5181 if (type is InterfaceType) { |
| 5175 if (!_typeSystem.isAssignableTo(type, _boolType)) { | 5182 if (!_typeSystem.isAssignableTo(type, _boolType)) { |
| 5176 _errorReporter.reportErrorForNode( | 5183 _errorReporter.reportErrorForNode( |
| 5177 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 5184 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 5178 } | 5185 } |
| 5179 } else if (type is FunctionType) { | 5186 } else if (type is FunctionType) { |
| 5180 if (type.typeArguments.length == 0 && | 5187 if (type.typeArguments.length == 0 && |
| 5181 !_typeSystem.isAssignableTo(type.returnType, _boolType)) { | 5188 !_typeSystem.isAssignableTo(type.returnType, _boolType)) { |
| 5182 _errorReporter.reportErrorForNode( | 5189 _errorReporter.reportErrorForNode( |
| (...skipping 1770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6953 class _InvocationCollector extends RecursiveAstVisitor { | 6960 class _InvocationCollector extends RecursiveAstVisitor { |
| 6954 final List<String> superCalls = <String>[]; | 6961 final List<String> superCalls = <String>[]; |
| 6955 | 6962 |
| 6956 @override | 6963 @override |
| 6957 visitMethodInvocation(MethodInvocation node) { | 6964 visitMethodInvocation(MethodInvocation node) { |
| 6958 if (node.target is SuperExpression) { | 6965 if (node.target is SuperExpression) { |
| 6959 superCalls.add(node.methodName.name); | 6966 superCalls.add(node.methodName.name); |
| 6960 } | 6967 } |
| 6961 } | 6968 } |
| 6962 } | 6969 } |
| OLD | NEW |