| 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 'package:analyzer/src/generated/static_type_analyzer.dart'; | 10 import 'package:analyzer/src/generated/static_type_analyzer.dart'; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 * The type representing the type 'int'. | 63 * The type representing the type 'int'. |
| 64 */ | 64 */ |
| 65 InterfaceType _intType; | 65 InterfaceType _intType; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * The object providing access to the types defined by the language. | 68 * The object providing access to the types defined by the language. |
| 69 */ | 69 */ |
| 70 final TypeProvider _typeProvider; | 70 final TypeProvider _typeProvider; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * The type system primitives |
| 74 */ |
| 75 TypeSystem _typeSystem; |
| 76 |
| 77 /** |
| 73 * The manager for the inheritance mappings. | 78 * The manager for the inheritance mappings. |
| 74 */ | 79 */ |
| 75 final InheritanceManager _inheritanceManager; | 80 final InheritanceManager _inheritanceManager; |
| 76 | 81 |
| 77 /** | 82 /** |
| 78 * A flag indicating whether the visitor is currently within a constructor | 83 * A flag indicating whether the visitor is currently within a constructor |
| 79 * declaration that is 'const'. | 84 * declaration that is 'const'. |
| 80 * | 85 * |
| 81 * See [visitConstructorDeclaration]. | 86 * See [visitConstructorDeclaration]. |
| 82 */ | 87 */ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 /** | 262 /** |
| 258 * If `true`, mixins are allowed to inherit from types other than Object, and | 263 * If `true`, mixins are allowed to inherit from types other than Object, and |
| 259 * are allowed to reference `super`. | 264 * are allowed to reference `super`. |
| 260 */ | 265 */ |
| 261 final bool enableSuperMixins; | 266 final bool enableSuperMixins; |
| 262 | 267 |
| 263 /** | 268 /** |
| 264 * Initialize a newly created error verifier. | 269 * Initialize a newly created error verifier. |
| 265 */ | 270 */ |
| 266 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, | 271 ErrorVerifier(this._errorReporter, this._currentLibrary, this._typeProvider, |
| 272 this._typeSystem, |
| 267 this._inheritanceManager, this.enableSuperMixins) { | 273 this._inheritanceManager, this.enableSuperMixins) { |
| 268 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; | 274 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; |
| 269 this._hasExtUri = _currentLibrary.hasExtUri; | 275 this._hasExtUri = _currentLibrary.hasExtUri; |
| 270 _isEnclosingConstructorConst = false; | 276 _isEnclosingConstructorConst = false; |
| 271 _isInCatchClause = false; | 277 _isInCatchClause = false; |
| 272 _isInStaticVariableDeclaration = false; | 278 _isInStaticVariableDeclaration = false; |
| 273 _isInInstanceVariableDeclaration = false; | 279 _isInInstanceVariableDeclaration = false; |
| 274 _isInInstanceVariableInitializer = false; | 280 _isInInstanceVariableInitializer = false; |
| 275 _isInConstructorInitializer = false; | 281 _isInConstructorInitializer = false; |
| 276 _isInStaticMethod = false; | 282 _isInStaticMethod = false; |
| (...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1347 _errorReporter.reportErrorForNode( | 1353 _errorReporter.reportErrorForNode( |
| 1348 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ | 1354 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ |
| 1349 overriddenParamName, | 1355 overriddenParamName, |
| 1350 overriddenExecutable.enclosingElement.displayName | 1356 overriddenExecutable.enclosingElement.displayName |
| 1351 ]); | 1357 ]); |
| 1352 return true; | 1358 return true; |
| 1353 } | 1359 } |
| 1354 } | 1360 } |
| 1355 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1361 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1356 if (overriddenFTReturnType != VoidTypeImpl.instance && | 1362 if (overriddenFTReturnType != VoidTypeImpl.instance && |
| 1357 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { | 1363 !_typeSystem.isAssignableTo(overridingFTReturnType,overriddenFTReturnTyp
e)) { |
| 1358 _errorReporter.reportTypeErrorForNode(!isGetter | 1364 _errorReporter.reportTypeErrorForNode(!isGetter |
| 1359 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1365 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1360 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1366 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
| 1361 errorNameTarget, [ | 1367 errorNameTarget, [ |
| 1362 overridingFTReturnType, | 1368 overridingFTReturnType, |
| 1363 overriddenFTReturnType, | 1369 overriddenFTReturnType, |
| 1364 overriddenExecutable.enclosingElement.displayName | 1370 overriddenExecutable.enclosingElement.displayName |
| 1365 ]); | 1371 ]); |
| 1366 return true; | 1372 return true; |
| 1367 } | 1373 } |
| 1368 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1374 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1369 if (parameterLocations == null) { | 1375 if (parameterLocations == null) { |
| 1370 return false; | 1376 return false; |
| 1371 } | 1377 } |
| 1372 int parameterIndex = 0; | 1378 int parameterIndex = 0; |
| 1373 for (int i = 0; i < overridingNormalPT.length; i++) { | 1379 for (int i = 0; i < overridingNormalPT.length; i++) { |
| 1374 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { | 1380 if (!_typeSystem.isAssignableTo(overridingNormalPT[i],overriddenNormalPT[i
])) { |
| 1375 _errorReporter.reportTypeErrorForNode(!isSetter | 1381 _errorReporter.reportTypeErrorForNode(!isSetter |
| 1376 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1382 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1377 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, | 1383 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, |
| 1378 parameterLocations[parameterIndex], [ | 1384 parameterLocations[parameterIndex], [ |
| 1379 overridingNormalPT[i], | 1385 overridingNormalPT[i], |
| 1380 overriddenNormalPT[i], | 1386 overriddenNormalPT[i], |
| 1381 overriddenExecutable.enclosingElement.displayName | 1387 overriddenExecutable.enclosingElement.displayName |
| 1382 ]); | 1388 ]); |
| 1383 return true; | 1389 return true; |
| 1384 } | 1390 } |
| 1385 parameterIndex++; | 1391 parameterIndex++; |
| 1386 } | 1392 } |
| 1387 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 1393 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
| 1388 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 1394 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
| 1389 if (!overridingPositionalPT[i] | 1395 if (!_typeSystem |
| 1390 .isAssignableTo(overriddenPositionalPT[i])) { | 1396 .isAssignableTo(overridingPositionalPT[i], overriddenPositionalPT[i]))
{ |
| 1391 _errorReporter.reportTypeErrorForNode( | 1397 _errorReporter.reportTypeErrorForNode( |
| 1392 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, | 1398 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, |
| 1393 parameterLocations[parameterIndex], [ | 1399 parameterLocations[parameterIndex], [ |
| 1394 overridingPositionalPT[i], | 1400 overridingPositionalPT[i], |
| 1395 overriddenPositionalPT[i], | 1401 overriddenPositionalPT[i], |
| 1396 overriddenExecutable.enclosingElement.displayName | 1402 overriddenExecutable.enclosingElement.displayName |
| 1397 ]); | 1403 ]); |
| 1398 return true; | 1404 return true; |
| 1399 } | 1405 } |
| 1400 parameterIndex++; | 1406 parameterIndex++; |
| 1401 } | 1407 } |
| 1402 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & | 1408 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & |
| 1403 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES | 1409 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES |
| 1404 for (String overriddenName in overriddenNamedPT.keys) { | 1410 for (String overriddenName in overriddenNamedPT.keys) { |
| 1405 DartType overridingType = overridingNamedPT[overriddenName]; | 1411 DartType overridingType = overridingNamedPT[overriddenName]; |
| 1406 if (overridingType == null) { | 1412 if (overridingType == null) { |
| 1407 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been | 1413 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been |
| 1408 // created above if this could be reached. | 1414 // created above if this could be reached. |
| 1409 continue; | 1415 continue; |
| 1410 } | 1416 } |
| 1411 DartType overriddenType = overriddenNamedPT[overriddenName]; | 1417 DartType overriddenType = overriddenNamedPT[overriddenName]; |
| 1412 if (!overriddenType.isAssignableTo(overridingType)) { | 1418 if (!_typeSystem.isAssignableTo(overriddenType,overridingType)) { |
| 1413 // lookup the parameter for the error to select | 1419 // lookup the parameter for the error to select |
| 1414 ParameterElement parameterToSelect = null; | 1420 ParameterElement parameterToSelect = null; |
| 1415 AstNode parameterLocationToSelect = null; | 1421 AstNode parameterLocationToSelect = null; |
| 1416 for (int i = 0; i < parameters.length; i++) { | 1422 for (int i = 0; i < parameters.length; i++) { |
| 1417 ParameterElement parameter = parameters[i]; | 1423 ParameterElement parameter = parameters[i]; |
| 1418 if (parameter.parameterKind == ParameterKind.NAMED && | 1424 if (parameter.parameterKind == ParameterKind.NAMED && |
| 1419 overriddenName == parameter.name) { | 1425 overriddenName == parameter.name) { |
| 1420 parameterToSelect = parameter; | 1426 parameterToSelect = parameter; |
| 1421 parameterLocationToSelect = parameterLocations[i]; | 1427 parameterLocationToSelect = parameterLocations[i]; |
| 1422 break; | 1428 break; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1729 } | 1735 } |
| 1730 return false; | 1736 return false; |
| 1731 } | 1737 } |
| 1732 FunctionType redirectedType = redirectedElement.type; | 1738 FunctionType redirectedType = redirectedElement.type; |
| 1733 DartType redirectedReturnType = redirectedType.returnType; | 1739 DartType redirectedReturnType = redirectedType.returnType; |
| 1734 // | 1740 // |
| 1735 // Report specific problem when return type is incompatible | 1741 // Report specific problem when return type is incompatible |
| 1736 // | 1742 // |
| 1737 FunctionType constructorType = declaration.element.type; | 1743 FunctionType constructorType = declaration.element.type; |
| 1738 DartType constructorReturnType = constructorType.returnType; | 1744 DartType constructorReturnType = constructorType.returnType; |
| 1739 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { | 1745 if (!_typeSystem.isAssignableTo(redirectedReturnType,constructorReturnType))
{ |
| 1740 _errorReporter.reportErrorForNode( | 1746 _errorReporter.reportErrorForNode( |
| 1741 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, | 1747 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, |
| 1742 redirectedConstructor, [redirectedReturnType, constructorReturnType]); | 1748 redirectedConstructor, [redirectedReturnType, constructorReturnType]); |
| 1743 return true; | 1749 return true; |
| 1744 } | 1750 } |
| 1745 // | 1751 // |
| 1746 // Check parameters | 1752 // Check parameters |
| 1747 // | 1753 // |
| 1748 if (!redirectedType.isSubtypeOf(constructorType)) { | 1754 if (!_typeSystem.isSubtypeOf(redirectedType,constructorType)) { |
| 1749 _errorReporter.reportErrorForNode( | 1755 _errorReporter.reportErrorForNode( |
| 1750 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, | 1756 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, |
| 1751 redirectedConstructor, [redirectedType, constructorType]); | 1757 redirectedConstructor, [redirectedType, constructorType]); |
| 1752 return true; | 1758 return true; |
| 1753 } | 1759 } |
| 1754 return false; | 1760 return false; |
| 1755 } | 1761 } |
| 1756 | 1762 |
| 1757 /** | 1763 /** |
| 1758 * Check that the return [statement] of the form <i>return e;</i> is not in a | 1764 * Check that the return [statement] of the form <i>return e;</i> is not in a |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1784 return false; | 1790 return false; |
| 1785 } | 1791 } |
| 1786 _errorReporter.reportErrorForNode( | 1792 _errorReporter.reportErrorForNode( |
| 1787 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, | 1793 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, |
| 1788 returnExpression); | 1794 returnExpression); |
| 1789 return true; | 1795 return true; |
| 1790 } | 1796 } |
| 1791 // RETURN_WITHOUT_VALUE | 1797 // RETURN_WITHOUT_VALUE |
| 1792 if (returnExpression == null) { | 1798 if (returnExpression == null) { |
| 1793 if (_inGenerator || | 1799 if (_inGenerator || |
| 1794 _computeReturnTypeForMethod(null) | 1800 _typeSystem |
| 1795 .isAssignableTo(expectedReturnType)) { | 1801 .isAssignableTo(_computeReturnTypeForMethod(null), expectedReturnType)
) { |
| 1796 return false; | 1802 return false; |
| 1797 } | 1803 } |
| 1798 _hasReturnWithoutValue = true; | 1804 _hasReturnWithoutValue = true; |
| 1799 _errorReporter.reportErrorForNode( | 1805 _errorReporter.reportErrorForNode( |
| 1800 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); | 1806 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); |
| 1801 return true; | 1807 return true; |
| 1802 } else if (_inGenerator) { | 1808 } else if (_inGenerator) { |
| 1803 // RETURN_IN_GENERATOR | 1809 // RETURN_IN_GENERATOR |
| 1804 _errorReporter.reportErrorForNode( | 1810 _errorReporter.reportErrorForNode( |
| 1805 CompileTimeErrorCode.RETURN_IN_GENERATOR, statement); | 1811 CompileTimeErrorCode.RETURN_IN_GENERATOR, statement); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and | 1867 * [StaticWarningCode.MAP_KEY_TYPE_NOT_ASSIGNABLE], and |
| 1862 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. | 1868 * [StaticWarningCode.MAP_VALUE_TYPE_NOT_ASSIGNABLE]. |
| 1863 */ | 1869 */ |
| 1864 bool _checkForArgumentTypeNotAssignable(Expression expression, | 1870 bool _checkForArgumentTypeNotAssignable(Expression expression, |
| 1865 DartType expectedStaticType, DartType actualStaticType, | 1871 DartType expectedStaticType, DartType actualStaticType, |
| 1866 ErrorCode errorCode) { | 1872 ErrorCode errorCode) { |
| 1867 // | 1873 // |
| 1868 // Warning case: test static type information | 1874 // Warning case: test static type information |
| 1869 // | 1875 // |
| 1870 if (actualStaticType != null && expectedStaticType != null) { | 1876 if (actualStaticType != null && expectedStaticType != null) { |
| 1871 if (!actualStaticType.isAssignableTo(expectedStaticType)) { | 1877 if (!_typeSystem.isAssignableTo(actualStaticType,expectedStaticType)) { |
| 1872 _errorReporter.reportTypeErrorForNode( | 1878 _errorReporter.reportTypeErrorForNode( |
| 1873 errorCode, expression, [actualStaticType, expectedStaticType]); | 1879 errorCode, expression, [actualStaticType, expectedStaticType]); |
| 1874 return true; | 1880 return true; |
| 1875 } | 1881 } |
| 1876 } | 1882 } |
| 1877 return false; | 1883 return false; |
| 1878 } | 1884 } |
| 1879 | 1885 |
| 1880 /** | 1886 /** |
| 1881 * Verify that the given [argument] can be assigned to its corresponding | 1887 * Verify that the given [argument] can be assigned to its corresponding |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1948 */ | 1954 */ |
| 1949 bool _checkForAssignability(Expression expression, InterfaceType type, | 1955 bool _checkForAssignability(Expression expression, InterfaceType type, |
| 1950 ErrorCode errorCode, List<Object> arguments) { | 1956 ErrorCode errorCode, List<Object> arguments) { |
| 1951 if (expression == null) { | 1957 if (expression == null) { |
| 1952 return false; | 1958 return false; |
| 1953 } | 1959 } |
| 1954 DartType expressionType = expression.staticType; | 1960 DartType expressionType = expression.staticType; |
| 1955 if (expressionType == null) { | 1961 if (expressionType == null) { |
| 1956 return false; | 1962 return false; |
| 1957 } | 1963 } |
| 1958 if (expressionType.isAssignableTo(type)) { | 1964 if (_typeSystem.isAssignableTo(expressionType, type)) { |
| 1959 return false; | 1965 return false; |
| 1960 } | 1966 } |
| 1961 _errorReporter.reportErrorForNode(errorCode, expression, arguments); | 1967 _errorReporter.reportErrorForNode(errorCode, expression, arguments); |
| 1962 return true; | 1968 return true; |
| 1963 } | 1969 } |
| 1964 | 1970 |
| 1965 /** | 1971 /** |
| 1966 * Verify that the given [expression] is not final. | 1972 * Verify that the given [expression] is not final. |
| 1967 * | 1973 * |
| 1968 * See [StaticWarningCode.ASSIGNMENT_TO_CONST], | 1974 * See [StaticWarningCode.ASSIGNMENT_TO_CONST], |
| (...skipping 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3206 // prepare expression type | 3212 // prepare expression type |
| 3207 Expression expression = initializer.expression; | 3213 Expression expression = initializer.expression; |
| 3208 if (expression == null) { | 3214 if (expression == null) { |
| 3209 return false; | 3215 return false; |
| 3210 } | 3216 } |
| 3211 // test the static type of the expression | 3217 // test the static type of the expression |
| 3212 DartType staticType = getStaticType(expression); | 3218 DartType staticType = getStaticType(expression); |
| 3213 if (staticType == null) { | 3219 if (staticType == null) { |
| 3214 return false; | 3220 return false; |
| 3215 } | 3221 } |
| 3216 if (staticType.isAssignableTo(fieldType)) { | 3222 if (_typeSystem.isAssignableTo(staticType, fieldType)) { |
| 3217 return false; | 3223 return false; |
| 3218 } | 3224 } |
| 3219 // report problem | 3225 // report problem |
| 3220 if (_isEnclosingConstructorConst) { | 3226 if (_isEnclosingConstructorConst) { |
| 3221 // TODO(paulberry): this error should be based on the actual type of the | 3227 // TODO(paulberry): this error should be based on the actual type of the |
| 3222 // constant, not the static type. See dartbug.com/21119. | 3228 // constant, not the static type. See dartbug.com/21119. |
| 3223 _errorReporter.reportTypeErrorForNode( | 3229 _errorReporter.reportTypeErrorForNode( |
| 3224 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, | 3230 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, |
| 3225 expression, [staticType, fieldType]); | 3231 expression, [staticType, fieldType]); |
| 3226 } | 3232 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3354 * respectively. If not, report the error using [returnType]. | 3360 * respectively. If not, report the error using [returnType]. |
| 3355 */ | 3361 */ |
| 3356 void _checkForIllegalReturnType(TypeName returnType) { | 3362 void _checkForIllegalReturnType(TypeName returnType) { |
| 3357 if (returnType == null) { | 3363 if (returnType == null) { |
| 3358 // No declared return type, so the return type must be dynamic, which is | 3364 // No declared return type, so the return type must be dynamic, which is |
| 3359 // assignable to everything. | 3365 // assignable to everything. |
| 3360 return; | 3366 return; |
| 3361 } | 3367 } |
| 3362 if (_enclosingFunction.isAsynchronous) { | 3368 if (_enclosingFunction.isAsynchronous) { |
| 3363 if (_enclosingFunction.isGenerator) { | 3369 if (_enclosingFunction.isGenerator) { |
| 3364 if (!_enclosingFunction.returnType | 3370 if (!_typeSystem.isAssignableTo(_enclosingFunction.returnType,_typeProvi
der.streamDynamicType)) { |
| 3365 .isAssignableTo(_typeProvider.streamDynamicType)) { | |
| 3366 _errorReporter.reportErrorForNode( | 3371 _errorReporter.reportErrorForNode( |
| 3367 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, | 3372 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, |
| 3368 returnType); | 3373 returnType); |
| 3369 } | 3374 } |
| 3370 } else { | 3375 } else { |
| 3371 if (!_enclosingFunction.returnType | 3376 if (!_typeSystem.isAssignableTo(_enclosingFunction.returnType,_typeProvi
der.futureDynamicType)) { |
| 3372 .isAssignableTo(_typeProvider.futureDynamicType)) { | |
| 3373 _errorReporter.reportErrorForNode( | 3377 _errorReporter.reportErrorForNode( |
| 3374 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, returnType); | 3378 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, returnType); |
| 3375 } | 3379 } |
| 3376 } | 3380 } |
| 3377 } else if (_enclosingFunction.isGenerator) { | 3381 } else if (_enclosingFunction.isGenerator) { |
| 3378 if (!_enclosingFunction.returnType | 3382 if (!_typeSystem.isAssignableTo(_enclosingFunction.returnType,_typeProvide
r.iterableDynamicType)) { |
| 3379 .isAssignableTo(_typeProvider.iterableDynamicType)) { | |
| 3380 _errorReporter.reportErrorForNode( | 3383 _errorReporter.reportErrorForNode( |
| 3381 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, | 3384 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, |
| 3382 returnType); | 3385 returnType); |
| 3383 } | 3386 } |
| 3384 } | 3387 } |
| 3385 } | 3388 } |
| 3386 | 3389 |
| 3387 /** | 3390 /** |
| 3388 * Verify that the given implements [clause] does not implement classes that | 3391 * Verify that the given implements [clause] does not implement classes that |
| 3389 * are deferred. | 3392 * are deferred. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3742 */ | 3745 */ |
| 3743 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { | 3746 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { |
| 3744 if (lhs == null || rhs == null) { | 3747 if (lhs == null || rhs == null) { |
| 3745 return false; | 3748 return false; |
| 3746 } | 3749 } |
| 3747 VariableElement leftVariableElement = getVariableElement(lhs); | 3750 VariableElement leftVariableElement = getVariableElement(lhs); |
| 3748 DartType leftType = (leftVariableElement == null) | 3751 DartType leftType = (leftVariableElement == null) |
| 3749 ? getStaticType(lhs) | 3752 ? getStaticType(lhs) |
| 3750 : leftVariableElement.type; | 3753 : leftVariableElement.type; |
| 3751 DartType staticRightType = getStaticType(rhs); | 3754 DartType staticRightType = getStaticType(rhs); |
| 3752 if (!staticRightType.isAssignableTo(leftType)) { | 3755 if (!_typeSystem.isAssignableTo(staticRightType,leftType)) { |
| 3753 _errorReporter.reportTypeErrorForNode( | 3756 _errorReporter.reportTypeErrorForNode( |
| 3754 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [ | 3757 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [ |
| 3755 staticRightType, | 3758 staticRightType, |
| 3756 leftType | 3759 leftType |
| 3757 ]); | 3760 ]); |
| 3758 return true; | 3761 return true; |
| 3759 } | 3762 } |
| 3760 return false; | 3763 return false; |
| 3761 } | 3764 } |
| 3762 | 3765 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3777 ? getStaticType(lhs) | 3780 ? getStaticType(lhs) |
| 3778 : leftVariableElement.type; | 3781 : leftVariableElement.type; |
| 3779 MethodElement invokedMethod = assignment.staticElement; | 3782 MethodElement invokedMethod = assignment.staticElement; |
| 3780 if (invokedMethod == null) { | 3783 if (invokedMethod == null) { |
| 3781 return false; | 3784 return false; |
| 3782 } | 3785 } |
| 3783 DartType rightType = invokedMethod.type.returnType; | 3786 DartType rightType = invokedMethod.type.returnType; |
| 3784 if (leftType == null || rightType == null) { | 3787 if (leftType == null || rightType == null) { |
| 3785 return false; | 3788 return false; |
| 3786 } | 3789 } |
| 3787 if (!rightType.isAssignableTo(leftType)) { | 3790 if (!_typeSystem.isAssignableTo(rightType,leftType)) { |
| 3788 _errorReporter.reportTypeErrorForNode( | 3791 _errorReporter.reportTypeErrorForNode( |
| 3789 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType, leftType]); | 3792 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType, leftType]); |
| 3790 return true; | 3793 return true; |
| 3791 } | 3794 } |
| 3792 return false; | 3795 return false; |
| 3793 } | 3796 } |
| 3794 | 3797 |
| 3795 /** | 3798 /** |
| 3796 * Check the given [initializer] to ensure that the field being initialized is | 3799 * Check the given [initializer] to ensure that the field being initialized is |
| 3797 * a valid field. The [fieldName] is the field name from the | 3800 * a valid field. The [fieldName] is the field name from the |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4044 getterType = _getGetterType(propertyAccessorElement); | 4047 getterType = _getGetterType(propertyAccessorElement); |
| 4045 setterType = _getSetterType(counterpartAccessor); | 4048 setterType = _getSetterType(counterpartAccessor); |
| 4046 } else if (propertyAccessorElement.isSetter) { | 4049 } else if (propertyAccessorElement.isSetter) { |
| 4047 setterType = _getSetterType(propertyAccessorElement); | 4050 setterType = _getSetterType(propertyAccessorElement); |
| 4048 getterType = _getGetterType(counterpartAccessor); | 4051 getterType = _getGetterType(counterpartAccessor); |
| 4049 } | 4052 } |
| 4050 // If either types are not assignable to each other, report an error | 4053 // If either types are not assignable to each other, report an error |
| 4051 // (if the getter is null, it is dynamic which is assignable to everything). | 4054 // (if the getter is null, it is dynamic which is assignable to everything). |
| 4052 if (setterType != null && | 4055 if (setterType != null && |
| 4053 getterType != null && | 4056 getterType != null && |
| 4054 !getterType.isAssignableTo(setterType)) { | 4057 !_typeSystem.isAssignableTo(getterType,setterType)) { |
| 4055 if (enclosingClassForCounterpart == null) { | 4058 if (enclosingClassForCounterpart == null) { |
| 4056 _errorReporter.reportTypeErrorForNode( | 4059 _errorReporter.reportTypeErrorForNode( |
| 4057 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, | 4060 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, |
| 4058 accessorDeclaration, [accessorTextName, setterType, getterType]); | 4061 accessorDeclaration, [accessorTextName, setterType, getterType]); |
| 4059 return true; | 4062 return true; |
| 4060 } else { | 4063 } else { |
| 4061 _errorReporter.reportTypeErrorForNode( | 4064 _errorReporter.reportTypeErrorForNode( |
| 4062 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, | 4065 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, |
| 4063 accessorDeclaration, [ | 4066 accessorDeclaration, [ |
| 4064 accessorTextName, | 4067 accessorTextName, |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4433 if ((elt is MethodElement && !elt.isAbstract) || | 4436 if ((elt is MethodElement && !elt.isAbstract) || |
| 4434 (elt is PropertyAccessorElement && !elt.isAbstract)) { | 4437 (elt is PropertyAccessorElement && !elt.isAbstract)) { |
| 4435 // Since we are comparing two function types, we need to do the | 4438 // Since we are comparing two function types, we need to do the |
| 4436 // appropriate type substitutions first (). | 4439 // appropriate type substitutions first (). |
| 4437 FunctionType foundConcreteFT = _inheritanceManager | 4440 FunctionType foundConcreteFT = _inheritanceManager |
| 4438 .substituteTypeArgumentsInMemberFromInheritance( | 4441 .substituteTypeArgumentsInMemberFromInheritance( |
| 4439 concreteType, memberName, enclosingType); | 4442 concreteType, memberName, enclosingType); |
| 4440 FunctionType requiredMemberFT = _inheritanceManager | 4443 FunctionType requiredMemberFT = _inheritanceManager |
| 4441 .substituteTypeArgumentsInMemberFromInheritance( | 4444 .substituteTypeArgumentsInMemberFromInheritance( |
| 4442 requiredMemberType, memberName, enclosingType); | 4445 requiredMemberType, memberName, enclosingType); |
| 4443 if (foundConcreteFT.isSubtypeOf(requiredMemberFT)) { | 4446 if (_typeSystem.isSubtypeOf(foundConcreteFT,requiredMemberFT)) { |
| 4444 continue; | 4447 continue; |
| 4445 } | 4448 } |
| 4446 } | 4449 } |
| 4447 } | 4450 } |
| 4448 // The not qualifying concrete executable element was found, add it to the | 4451 // The not qualifying concrete executable element was found, add it to the |
| 4449 // list. | 4452 // list. |
| 4450 missingOverrides.add(executableElt); | 4453 missingOverrides.add(executableElt); |
| 4451 } | 4454 } |
| 4452 // Now that we have the set of missing overrides, generate a warning on this | 4455 // Now that we have the set of missing overrides, generate a warning on this |
| 4453 // class. | 4456 // class. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4526 } | 4529 } |
| 4527 | 4530 |
| 4528 /** | 4531 /** |
| 4529 * Check to ensure that the [condition] is of type bool, are. Otherwise an | 4532 * Check to ensure that the [condition] is of type bool, are. Otherwise an |
| 4530 * error is reported on the expression. | 4533 * error is reported on the expression. |
| 4531 * | 4534 * |
| 4532 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. | 4535 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. |
| 4533 */ | 4536 */ |
| 4534 bool _checkForNonBoolCondition(Expression condition) { | 4537 bool _checkForNonBoolCondition(Expression condition) { |
| 4535 DartType conditionType = getStaticType(condition); | 4538 DartType conditionType = getStaticType(condition); |
| 4536 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4539 if (conditionType != null && !_typeSystem.isAssignableTo(conditionType,_bool
Type)) { |
| 4537 _errorReporter.reportErrorForNode( | 4540 _errorReporter.reportErrorForNode( |
| 4538 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); | 4541 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); |
| 4539 return true; | 4542 return true; |
| 4540 } | 4543 } |
| 4541 return false; | 4544 return false; |
| 4542 } | 4545 } |
| 4543 | 4546 |
| 4544 /** | 4547 /** |
| 4545 * Verify that the given assert [statement] has either a 'bool' or | 4548 * Verify that the given assert [statement] has either a 'bool' or |
| 4546 * '() -> bool' input. | 4549 * '() -> bool' input. |
| 4547 * | 4550 * |
| 4548 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. | 4551 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. |
| 4549 */ | 4552 */ |
| 4550 bool _checkForNonBoolExpression(AssertStatement statement) { | 4553 bool _checkForNonBoolExpression(AssertStatement statement) { |
| 4551 Expression expression = statement.condition; | 4554 Expression expression = statement.condition; |
| 4552 DartType type = getStaticType(expression); | 4555 DartType type = getStaticType(expression); |
| 4553 if (type is InterfaceType) { | 4556 if (type is InterfaceType) { |
| 4554 if (!type.isAssignableTo(_boolType)) { | 4557 if (!_typeSystem.isAssignableTo(type,_boolType)) { |
| 4555 _errorReporter.reportErrorForNode( | 4558 _errorReporter.reportErrorForNode( |
| 4556 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4559 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 4557 return true; | 4560 return true; |
| 4558 } | 4561 } |
| 4559 } else if (type is FunctionType) { | 4562 } else if (type is FunctionType) { |
| 4560 FunctionType functionType = type; | 4563 FunctionType functionType = type; |
| 4561 if (functionType.typeArguments.length == 0 && | 4564 if (functionType.typeArguments.length == 0 && |
| 4562 !functionType.returnType.isAssignableTo(_boolType)) { | 4565 !_typeSystem.isAssignableTo(functionType.returnType,_boolType)) { |
| 4563 _errorReporter.reportErrorForNode( | 4566 _errorReporter.reportErrorForNode( |
| 4564 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4567 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 4565 return true; | 4568 return true; |
| 4566 } | 4569 } |
| 4567 } | 4570 } |
| 4568 return false; | 4571 return false; |
| 4569 } | 4572 } |
| 4570 | 4573 |
| 4571 /** | 4574 /** |
| 4572 * Checks to ensure that the given [expression] is assignable to bool. | 4575 * Checks to ensure that the given [expression] is assignable to bool. |
| 4573 * | 4576 * |
| 4574 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. | 4577 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. |
| 4575 */ | 4578 */ |
| 4576 bool _checkForNonBoolNegationExpression(Expression expression) { | 4579 bool _checkForNonBoolNegationExpression(Expression expression) { |
| 4577 DartType conditionType = getStaticType(expression); | 4580 DartType conditionType = getStaticType(expression); |
| 4578 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4581 if (conditionType != null && !_typeSystem.isAssignableTo(conditionType,_bool
Type)) { |
| 4579 _errorReporter.reportErrorForNode( | 4582 _errorReporter.reportErrorForNode( |
| 4580 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, expression); | 4583 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, expression); |
| 4581 return true; | 4584 return true; |
| 4582 } | 4585 } |
| 4583 return false; | 4586 return false; |
| 4584 } | 4587 } |
| 4585 | 4588 |
| 4586 /** | 4589 /** |
| 4587 * Verify the given map [literal] either: | 4590 * Verify the given map [literal] either: |
| 4588 * * has `const modifier` | 4591 * * has `const modifier` |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4963 return false; | 4966 return false; |
| 4964 } | 4967 } |
| 4965 _errorReporter.reportTypeErrorForNode( | 4968 _errorReporter.reportTypeErrorForNode( |
| 4966 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 4969 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ |
| 4967 staticReturnType, | 4970 staticReturnType, |
| 4968 expectedReturnType, | 4971 expectedReturnType, |
| 4969 _enclosingFunction.displayName | 4972 _enclosingFunction.displayName |
| 4970 ]); | 4973 ]); |
| 4971 return true; | 4974 return true; |
| 4972 } | 4975 } |
| 4973 if (staticReturnType.isAssignableTo(expectedReturnType)) { | 4976 if (_typeSystem.isAssignableTo(staticReturnType, expectedReturnType)) { |
| 4974 return false; | 4977 return false; |
| 4975 } | 4978 } |
| 4976 _errorReporter.reportTypeErrorForNode( | 4979 _errorReporter.reportTypeErrorForNode( |
| 4977 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 4980 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ |
| 4978 staticReturnType, | 4981 staticReturnType, |
| 4979 expectedReturnType, | 4982 expectedReturnType, |
| 4980 _enclosingFunction.displayName | 4983 _enclosingFunction.displayName |
| 4981 ]); | 4984 ]); |
| 4982 return true; | 4985 return true; |
| 4983 // TODO(brianwilkerson) Define a hint corresponding to the warning and | 4986 // TODO(brianwilkerson) Define a hint corresponding to the warning and |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5041 NodeList<SwitchMember> members = statement.members; | 5044 NodeList<SwitchMember> members = statement.members; |
| 5042 for (SwitchMember switchMember in members) { | 5045 for (SwitchMember switchMember in members) { |
| 5043 if (switchMember is! SwitchCase) { | 5046 if (switchMember is! SwitchCase) { |
| 5044 continue; | 5047 continue; |
| 5045 } | 5048 } |
| 5046 SwitchCase switchCase = switchMember as SwitchCase; | 5049 SwitchCase switchCase = switchMember as SwitchCase; |
| 5047 // prepare 'case' type | 5050 // prepare 'case' type |
| 5048 Expression caseExpression = switchCase.expression; | 5051 Expression caseExpression = switchCase.expression; |
| 5049 DartType caseType = getStaticType(caseExpression); | 5052 DartType caseType = getStaticType(caseExpression); |
| 5050 // check types | 5053 // check types |
| 5051 if (expressionType.isAssignableTo(caseType)) { | 5054 if (_typeSystem.isAssignableTo(expressionType, caseType)) { |
| 5052 return false; | 5055 return false; |
| 5053 } | 5056 } |
| 5054 // report problem | 5057 // report problem |
| 5055 _errorReporter.reportErrorForNode( | 5058 _errorReporter.reportErrorForNode( |
| 5056 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, expression, [ | 5059 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, expression, [ |
| 5057 expressionType, | 5060 expressionType, |
| 5058 caseType | 5061 caseType |
| 5059 ]); | 5062 ]); |
| 5060 return true; | 5063 return true; |
| 5061 } | 5064 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5124 bool foundError = false; | 5127 bool foundError = false; |
| 5125 for (int i = 0; i < loopThroughIndex; i++) { | 5128 for (int i = 0; i < loopThroughIndex; i++) { |
| 5126 TypeName argTypeName = typeNameArgList[i]; | 5129 TypeName argTypeName = typeNameArgList[i]; |
| 5127 DartType argType = argTypeName.type; | 5130 DartType argType = argTypeName.type; |
| 5128 DartType boundType = boundingElts[i].bound; | 5131 DartType boundType = boundingElts[i].bound; |
| 5129 if (argType != null && boundType != null) { | 5132 if (argType != null && boundType != null) { |
| 5130 if (typeArguments.length != 0 && | 5133 if (typeArguments.length != 0 && |
| 5131 typeArguments.length == typeParameters.length) { | 5134 typeArguments.length == typeParameters.length) { |
| 5132 boundType = boundType.substitute2(typeArguments, typeParameters); | 5135 boundType = boundType.substitute2(typeArguments, typeParameters); |
| 5133 } | 5136 } |
| 5134 if (!argType.isSubtypeOf(boundType)) { | 5137 if (!_typeSystem.isSubtypeOf(argType,boundType)) { |
| 5135 ErrorCode errorCode; | 5138 ErrorCode errorCode; |
| 5136 if (_isInConstInstanceCreation) { | 5139 if (_isInConstInstanceCreation) { |
| 5137 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | 5140 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; |
| 5138 } else { | 5141 } else { |
| 5139 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | 5142 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; |
| 5140 } | 5143 } |
| 5141 _errorReporter.reportTypeErrorForNode( | 5144 _errorReporter.reportTypeErrorForNode( |
| 5142 errorCode, argTypeName, [argType, boundType]); | 5145 errorCode, argTypeName, [argType, boundType]); |
| 5143 foundError = true; | 5146 foundError = true; |
| 5144 } | 5147 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5311 if (fieldElement.isSynthetic) { | 5314 if (fieldElement.isSynthetic) { |
| 5312 _errorReporter.reportErrorForNode( | 5315 _errorReporter.reportErrorForNode( |
| 5313 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5316 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5314 parameter, [parameter.identifier.name]); | 5317 parameter, [parameter.identifier.name]); |
| 5315 } else if (fieldElement.isStatic) { | 5318 } else if (fieldElement.isStatic) { |
| 5316 _errorReporter.reportErrorForNode( | 5319 _errorReporter.reportErrorForNode( |
| 5317 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5320 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
| 5318 parameter, [parameter.identifier.name]); | 5321 parameter, [parameter.identifier.name]); |
| 5319 } else if (declaredType != null && | 5322 } else if (declaredType != null && |
| 5320 fieldType != null && | 5323 fieldType != null && |
| 5321 !declaredType.isAssignableTo(fieldType)) { | 5324 !_typeSystem.isAssignableTo(declaredType,fieldType)) { |
| 5322 _errorReporter.reportTypeErrorForNode( | 5325 _errorReporter.reportTypeErrorForNode( |
| 5323 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, | 5326 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, |
| 5324 parameter, [declaredType, fieldType]); | 5327 parameter, [declaredType, fieldType]); |
| 5325 } | 5328 } |
| 5326 } else { | 5329 } else { |
| 5327 if (fieldElement.isSynthetic) { | 5330 if (fieldElement.isSynthetic) { |
| 5328 _errorReporter.reportErrorForNode( | 5331 _errorReporter.reportErrorForNode( |
| 5329 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5332 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5330 parameter, [parameter.identifier.name]); | 5333 parameter, [parameter.identifier.name]); |
| 5331 } else if (fieldElement.isStatic) { | 5334 } else if (fieldElement.isStatic) { |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5467 DartType impliedReturnType; | 5470 DartType impliedReturnType; |
| 5468 if (isYieldEach) { | 5471 if (isYieldEach) { |
| 5469 impliedReturnType = staticYieldedType; | 5472 impliedReturnType = staticYieldedType; |
| 5470 } else if (_enclosingFunction.isAsynchronous) { | 5473 } else if (_enclosingFunction.isAsynchronous) { |
| 5471 impliedReturnType = | 5474 impliedReturnType = |
| 5472 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); | 5475 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); |
| 5473 } else { | 5476 } else { |
| 5474 impliedReturnType = | 5477 impliedReturnType = |
| 5475 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); | 5478 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); |
| 5476 } | 5479 } |
| 5477 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { | 5480 if (!_typeSystem.isAssignableTo(impliedReturnType,declaredReturnType)) { |
| 5478 _errorReporter.reportTypeErrorForNode( | 5481 _errorReporter.reportTypeErrorForNode( |
| 5479 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5482 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ |
| 5480 impliedReturnType, | 5483 impliedReturnType, |
| 5481 declaredReturnType | 5484 declaredReturnType |
| 5482 ]); | 5485 ]); |
| 5483 return true; | 5486 return true; |
| 5484 } | 5487 } |
| 5485 if (isYieldEach) { | 5488 if (isYieldEach) { |
| 5486 // Since the declared return type might have been "dynamic", we need to | 5489 // Since the declared return type might have been "dynamic", we need to |
| 5487 // also check that the implied return type is assignable to generic | 5490 // also check that the implied return type is assignable to generic |
| 5488 // Stream/Iterable. | 5491 // Stream/Iterable. |
| 5489 DartType requiredReturnType; | 5492 DartType requiredReturnType; |
| 5490 if (_enclosingFunction.isAsynchronous) { | 5493 if (_enclosingFunction.isAsynchronous) { |
| 5491 requiredReturnType = _typeProvider.streamDynamicType; | 5494 requiredReturnType = _typeProvider.streamDynamicType; |
| 5492 } else { | 5495 } else { |
| 5493 requiredReturnType = _typeProvider.iterableDynamicType; | 5496 requiredReturnType = _typeProvider.iterableDynamicType; |
| 5494 } | 5497 } |
| 5495 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { | 5498 if (!_typeSystem.isAssignableTo(impliedReturnType,requiredReturnType)) { |
| 5496 _errorReporter.reportTypeErrorForNode( | 5499 _errorReporter.reportTypeErrorForNode( |
| 5497 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ | 5500 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, yieldExpression, [ |
| 5498 impliedReturnType, | 5501 impliedReturnType, |
| 5499 requiredReturnType | 5502 requiredReturnType |
| 5500 ]); | 5503 ]); |
| 5501 return true; | 5504 return true; |
| 5502 } | 5505 } |
| 5503 } | 5506 } |
| 5504 return false; | 5507 return false; |
| 5505 } | 5508 } |
| 5506 | 5509 |
| 5507 /** | 5510 /** |
| 5508 * Verify that if the given class [declaration] implements the class Function | 5511 * Verify that if the given class [declaration] implements the class Function |
| 5509 * that it has a concrete implementation of the call method. | 5512 * that it has a concrete implementation of the call method. |
| 5510 * | 5513 * |
| 5511 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. | 5514 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. |
| 5512 */ | 5515 */ |
| 5513 bool _checkImplementsFunctionWithoutCall(ClassDeclaration declaration) { | 5516 bool _checkImplementsFunctionWithoutCall(ClassDeclaration declaration) { |
| 5514 if (declaration.isAbstract) { | 5517 if (declaration.isAbstract) { |
| 5515 return false; | 5518 return false; |
| 5516 } | 5519 } |
| 5517 ClassElement classElement = declaration.element; | 5520 ClassElement classElement = declaration.element; |
| 5518 if (classElement == null) { | 5521 if (classElement == null) { |
| 5519 return false; | 5522 return false; |
| 5520 } | 5523 } |
| 5521 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { | 5524 if (!_typeSystem.isSubtypeOf(classElement.type,_typeProvider.functionType))
{ |
| 5522 return false; | 5525 return false; |
| 5523 } | 5526 } |
| 5524 // If there is a noSuchMethod method, then don't report the warning, | 5527 // If there is a noSuchMethod method, then don't report the warning, |
| 5525 // see dartbug.com/16078 | 5528 // see dartbug.com/16078 |
| 5526 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != | 5529 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != |
| 5527 null) { | 5530 null) { |
| 5528 return false; | 5531 return false; |
| 5529 } | 5532 } |
| 5530 ExecutableElement callMethod = _inheritanceManager.lookupMember( | 5533 ExecutableElement callMethod = _inheritanceManager.lookupMember( |
| 5531 classElement, FunctionElement.CALL_METHOD_NAME); | 5534 classElement, FunctionElement.CALL_METHOD_NAME); |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5992 toCheck.add(type.element); | 5995 toCheck.add(type.element); |
| 5993 // type arguments | 5996 // type arguments |
| 5994 if (type is InterfaceType) { | 5997 if (type is InterfaceType) { |
| 5995 InterfaceType interfaceType = type; | 5998 InterfaceType interfaceType = type; |
| 5996 for (DartType typeArgument in interfaceType.typeArguments) { | 5999 for (DartType typeArgument in interfaceType.typeArguments) { |
| 5997 _addTypeToCheck(typeArgument); | 6000 _addTypeToCheck(typeArgument); |
| 5998 } | 6001 } |
| 5999 } | 6002 } |
| 6000 } | 6003 } |
| 6001 } | 6004 } |
| OLD | NEW |