| 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, |
| 267 this._inheritanceManager, this.enableSuperMixins) { | 272 this._typeSystem, this._inheritanceManager, this.enableSuperMixins) { |
| 268 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; | 273 this._isInSystemLibrary = _currentLibrary.source.isInSystemLibrary; |
| 269 this._hasExtUri = _currentLibrary.hasExtUri; | 274 this._hasExtUri = _currentLibrary.hasExtUri; |
| 270 _isEnclosingConstructorConst = false; | 275 _isEnclosingConstructorConst = false; |
| 271 _isInCatchClause = false; | 276 _isInCatchClause = false; |
| 272 _isInStaticVariableDeclaration = false; | 277 _isInStaticVariableDeclaration = false; |
| 273 _isInInstanceVariableDeclaration = false; | 278 _isInInstanceVariableDeclaration = false; |
| 274 _isInInstanceVariableInitializer = false; | 279 _isInInstanceVariableInitializer = false; |
| 275 _isInConstructorInitializer = false; | 280 _isInConstructorInitializer = false; |
| 276 _isInStaticMethod = false; | 281 _isInStaticMethod = false; |
| 277 _boolType = _typeProvider.boolType; | 282 _boolType = _typeProvider.boolType; |
| (...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 _errorReporter.reportErrorForNode( | 1358 _errorReporter.reportErrorForNode( |
| 1354 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ | 1359 StaticWarningCode.INVALID_OVERRIDE_NAMED, errorNameTarget, [ |
| 1355 overriddenParamName, | 1360 overriddenParamName, |
| 1356 overriddenExecutable.enclosingElement.displayName | 1361 overriddenExecutable.enclosingElement.displayName |
| 1357 ]); | 1362 ]); |
| 1358 return true; | 1363 return true; |
| 1359 } | 1364 } |
| 1360 } | 1365 } |
| 1361 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1366 // SWC.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1362 if (overriddenFTReturnType != VoidTypeImpl.instance && | 1367 if (overriddenFTReturnType != VoidTypeImpl.instance && |
| 1363 !overridingFTReturnType.isAssignableTo(overriddenFTReturnType)) { | 1368 !_typeSystem.isAssignableTo( |
| 1369 overridingFTReturnType, overriddenFTReturnType)) { |
| 1364 _errorReporter.reportTypeErrorForNode( | 1370 _errorReporter.reportTypeErrorForNode( |
| 1365 !isGetter | 1371 !isGetter |
| 1366 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE | 1372 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_RETURN_TYPE |
| 1367 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, | 1373 : StaticWarningCode.INVALID_GETTER_OVERRIDE_RETURN_TYPE, |
| 1368 errorNameTarget, | 1374 errorNameTarget, |
| 1369 [ | 1375 [ |
| 1370 overridingFTReturnType, | 1376 overridingFTReturnType, |
| 1371 overriddenFTReturnType, | 1377 overriddenFTReturnType, |
| 1372 overriddenExecutable.enclosingElement.displayName | 1378 overriddenExecutable.enclosingElement.displayName |
| 1373 ]); | 1379 ]); |
| 1374 return true; | 1380 return true; |
| 1375 } | 1381 } |
| 1376 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1382 // SWC.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1377 if (parameterLocations == null) { | 1383 if (parameterLocations == null) { |
| 1378 return false; | 1384 return false; |
| 1379 } | 1385 } |
| 1380 int parameterIndex = 0; | 1386 int parameterIndex = 0; |
| 1381 for (int i = 0; i < overridingNormalPT.length; i++) { | 1387 for (int i = 0; i < overridingNormalPT.length; i++) { |
| 1382 if (!overridingNormalPT[i].isAssignableTo(overriddenNormalPT[i])) { | 1388 if (!_typeSystem.isAssignableTo( |
| 1389 overridingNormalPT[i], overriddenNormalPT[i])) { |
| 1383 _errorReporter.reportTypeErrorForNode( | 1390 _errorReporter.reportTypeErrorForNode( |
| 1384 !isSetter | 1391 !isSetter |
| 1385 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE | 1392 ? StaticWarningCode.INVALID_METHOD_OVERRIDE_NORMAL_PARAM_TYPE |
| 1386 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, | 1393 : StaticWarningCode.INVALID_SETTER_OVERRIDE_NORMAL_PARAM_TYPE, |
| 1387 parameterLocations[parameterIndex], | 1394 parameterLocations[parameterIndex], |
| 1388 [ | 1395 [ |
| 1389 overridingNormalPT[i], | 1396 overridingNormalPT[i], |
| 1390 overriddenNormalPT[i], | 1397 overriddenNormalPT[i], |
| 1391 overriddenExecutable.enclosingElement.displayName | 1398 overriddenExecutable.enclosingElement.displayName |
| 1392 ]); | 1399 ]); |
| 1393 return true; | 1400 return true; |
| 1394 } | 1401 } |
| 1395 parameterIndex++; | 1402 parameterIndex++; |
| 1396 } | 1403 } |
| 1397 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE | 1404 // SWC.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE |
| 1398 for (int i = 0; i < overriddenPositionalPT.length; i++) { | 1405 for (int i = 0; i < overriddenPositionalPT.length; i++) { |
| 1399 if (!overridingPositionalPT[i] | 1406 if (!_typeSystem.isAssignableTo( |
| 1400 .isAssignableTo(overriddenPositionalPT[i])) { | 1407 overridingPositionalPT[i], overriddenPositionalPT[i])) { |
| 1401 _errorReporter.reportTypeErrorForNode( | 1408 _errorReporter.reportTypeErrorForNode( |
| 1402 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, | 1409 StaticWarningCode.INVALID_METHOD_OVERRIDE_OPTIONAL_PARAM_TYPE, |
| 1403 parameterLocations[parameterIndex], [ | 1410 parameterLocations[parameterIndex], [ |
| 1404 overridingPositionalPT[i], | 1411 overridingPositionalPT[i], |
| 1405 overriddenPositionalPT[i], | 1412 overriddenPositionalPT[i], |
| 1406 overriddenExecutable.enclosingElement.displayName | 1413 overriddenExecutable.enclosingElement.displayName |
| 1407 ]); | 1414 ]); |
| 1408 return true; | 1415 return true; |
| 1409 } | 1416 } |
| 1410 parameterIndex++; | 1417 parameterIndex++; |
| 1411 } | 1418 } |
| 1412 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & | 1419 // SWC.INVALID_METHOD_OVERRIDE_NAMED_PARAM_TYPE & |
| 1413 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES | 1420 // SWC.INVALID_OVERRIDE_DIFFERENT_DEFAULT_VALUES |
| 1414 for (String overriddenName in overriddenNamedPT.keys) { | 1421 for (String overriddenName in overriddenNamedPT.keys) { |
| 1415 DartType overridingType = overridingNamedPT[overriddenName]; | 1422 DartType overridingType = overridingNamedPT[overriddenName]; |
| 1416 if (overridingType == null) { | 1423 if (overridingType == null) { |
| 1417 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been | 1424 // Error, this is never reached- INVALID_OVERRIDE_NAMED would have been |
| 1418 // created above if this could be reached. | 1425 // created above if this could be reached. |
| 1419 continue; | 1426 continue; |
| 1420 } | 1427 } |
| 1421 DartType overriddenType = overriddenNamedPT[overriddenName]; | 1428 DartType overriddenType = overriddenNamedPT[overriddenName]; |
| 1422 if (!overriddenType.isAssignableTo(overridingType)) { | 1429 if (!_typeSystem.isAssignableTo(overriddenType, overridingType)) { |
| 1423 // lookup the parameter for the error to select | 1430 // lookup the parameter for the error to select |
| 1424 ParameterElement parameterToSelect = null; | 1431 ParameterElement parameterToSelect = null; |
| 1425 AstNode parameterLocationToSelect = null; | 1432 AstNode parameterLocationToSelect = null; |
| 1426 for (int i = 0; i < parameters.length; i++) { | 1433 for (int i = 0; i < parameters.length; i++) { |
| 1427 ParameterElement parameter = parameters[i]; | 1434 ParameterElement parameter = parameters[i]; |
| 1428 if (parameter.parameterKind == ParameterKind.NAMED && | 1435 if (parameter.parameterKind == ParameterKind.NAMED && |
| 1429 overriddenName == parameter.name) { | 1436 overriddenName == parameter.name) { |
| 1430 parameterToSelect = parameter; | 1437 parameterToSelect = parameter; |
| 1431 parameterLocationToSelect = parameterLocations[i]; | 1438 parameterLocationToSelect = parameterLocations[i]; |
| 1432 break; | 1439 break; |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1739 } | 1746 } |
| 1740 return false; | 1747 return false; |
| 1741 } | 1748 } |
| 1742 FunctionType redirectedType = redirectedElement.type; | 1749 FunctionType redirectedType = redirectedElement.type; |
| 1743 DartType redirectedReturnType = redirectedType.returnType; | 1750 DartType redirectedReturnType = redirectedType.returnType; |
| 1744 // | 1751 // |
| 1745 // Report specific problem when return type is incompatible | 1752 // Report specific problem when return type is incompatible |
| 1746 // | 1753 // |
| 1747 FunctionType constructorType = declaration.element.type; | 1754 FunctionType constructorType = declaration.element.type; |
| 1748 DartType constructorReturnType = constructorType.returnType; | 1755 DartType constructorReturnType = constructorType.returnType; |
| 1749 if (!redirectedReturnType.isAssignableTo(constructorReturnType)) { | 1756 if (!_typeSystem.isAssignableTo( |
| 1757 redirectedReturnType, constructorReturnType)) { |
| 1750 _errorReporter.reportErrorForNode( | 1758 _errorReporter.reportErrorForNode( |
| 1751 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, | 1759 StaticWarningCode.REDIRECT_TO_INVALID_RETURN_TYPE, |
| 1752 redirectedConstructor, | 1760 redirectedConstructor, |
| 1753 [redirectedReturnType, constructorReturnType]); | 1761 [redirectedReturnType, constructorReturnType]); |
| 1754 return true; | 1762 return true; |
| 1755 } | 1763 } |
| 1756 // | 1764 // |
| 1757 // Check parameters | 1765 // Check parameters |
| 1758 // | 1766 // |
| 1759 if (!redirectedType.isSubtypeOf(constructorType)) { | 1767 if (!_typeSystem.isSubtypeOf(redirectedType, constructorType)) { |
| 1760 _errorReporter.reportErrorForNode( | 1768 _errorReporter.reportErrorForNode( |
| 1761 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, | 1769 StaticWarningCode.REDIRECT_TO_INVALID_FUNCTION_TYPE, |
| 1762 redirectedConstructor, | 1770 redirectedConstructor, |
| 1763 [redirectedType, constructorType]); | 1771 [redirectedType, constructorType]); |
| 1764 return true; | 1772 return true; |
| 1765 } | 1773 } |
| 1766 return false; | 1774 return false; |
| 1767 } | 1775 } |
| 1768 | 1776 |
| 1769 /** | 1777 /** |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1796 return false; | 1804 return false; |
| 1797 } | 1805 } |
| 1798 _errorReporter.reportErrorForNode( | 1806 _errorReporter.reportErrorForNode( |
| 1799 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, | 1807 CompileTimeErrorCode.RETURN_IN_GENERATIVE_CONSTRUCTOR, |
| 1800 returnExpression); | 1808 returnExpression); |
| 1801 return true; | 1809 return true; |
| 1802 } | 1810 } |
| 1803 // RETURN_WITHOUT_VALUE | 1811 // RETURN_WITHOUT_VALUE |
| 1804 if (returnExpression == null) { | 1812 if (returnExpression == null) { |
| 1805 if (_inGenerator || | 1813 if (_inGenerator || |
| 1806 _computeReturnTypeForMethod(null) | 1814 _typeSystem.isAssignableTo( |
| 1807 .isAssignableTo(expectedReturnType)) { | 1815 _computeReturnTypeForMethod(null), expectedReturnType)) { |
| 1808 return false; | 1816 return false; |
| 1809 } | 1817 } |
| 1810 _hasReturnWithoutValue = true; | 1818 _hasReturnWithoutValue = true; |
| 1811 _errorReporter.reportErrorForNode( | 1819 _errorReporter.reportErrorForNode( |
| 1812 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); | 1820 StaticWarningCode.RETURN_WITHOUT_VALUE, statement); |
| 1813 return true; | 1821 return true; |
| 1814 } else if (_inGenerator) { | 1822 } else if (_inGenerator) { |
| 1815 // RETURN_IN_GENERATOR | 1823 // RETURN_IN_GENERATOR |
| 1816 _errorReporter.reportErrorForNode( | 1824 _errorReporter.reportErrorForNode( |
| 1817 CompileTimeErrorCode.RETURN_IN_GENERATOR, statement); | 1825 CompileTimeErrorCode.RETURN_IN_GENERATOR, statement); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1875 */ | 1883 */ |
| 1876 bool _checkForArgumentTypeNotAssignable( | 1884 bool _checkForArgumentTypeNotAssignable( |
| 1877 Expression expression, | 1885 Expression expression, |
| 1878 DartType expectedStaticType, | 1886 DartType expectedStaticType, |
| 1879 DartType actualStaticType, | 1887 DartType actualStaticType, |
| 1880 ErrorCode errorCode) { | 1888 ErrorCode errorCode) { |
| 1881 // | 1889 // |
| 1882 // Warning case: test static type information | 1890 // Warning case: test static type information |
| 1883 // | 1891 // |
| 1884 if (actualStaticType != null && expectedStaticType != null) { | 1892 if (actualStaticType != null && expectedStaticType != null) { |
| 1885 if (!actualStaticType.isAssignableTo(expectedStaticType)) { | 1893 if (!_typeSystem.isAssignableTo(actualStaticType, expectedStaticType)) { |
| 1886 _errorReporter.reportTypeErrorForNode( | 1894 _errorReporter.reportTypeErrorForNode( |
| 1887 errorCode, expression, [actualStaticType, expectedStaticType]); | 1895 errorCode, expression, [actualStaticType, expectedStaticType]); |
| 1888 return true; | 1896 return true; |
| 1889 } | 1897 } |
| 1890 } | 1898 } |
| 1891 return false; | 1899 return false; |
| 1892 } | 1900 } |
| 1893 | 1901 |
| 1894 /** | 1902 /** |
| 1895 * Verify that the given [argument] can be assigned to its corresponding | 1903 * Verify that the given [argument] can be assigned to its corresponding |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1964 */ | 1972 */ |
| 1965 bool _checkForAssignability(Expression expression, InterfaceType type, | 1973 bool _checkForAssignability(Expression expression, InterfaceType type, |
| 1966 ErrorCode errorCode, List<Object> arguments) { | 1974 ErrorCode errorCode, List<Object> arguments) { |
| 1967 if (expression == null) { | 1975 if (expression == null) { |
| 1968 return false; | 1976 return false; |
| 1969 } | 1977 } |
| 1970 DartType expressionType = expression.staticType; | 1978 DartType expressionType = expression.staticType; |
| 1971 if (expressionType == null) { | 1979 if (expressionType == null) { |
| 1972 return false; | 1980 return false; |
| 1973 } | 1981 } |
| 1974 if (expressionType.isAssignableTo(type)) { | 1982 if (_typeSystem.isAssignableTo(expressionType, type)) { |
| 1975 return false; | 1983 return false; |
| 1976 } | 1984 } |
| 1977 _errorReporter.reportErrorForNode(errorCode, expression, arguments); | 1985 _errorReporter.reportErrorForNode(errorCode, expression, arguments); |
| 1978 return true; | 1986 return true; |
| 1979 } | 1987 } |
| 1980 | 1988 |
| 1981 /** | 1989 /** |
| 1982 * Verify that the given [expression] is not final. | 1990 * Verify that the given [expression] is not final. |
| 1983 * | 1991 * |
| 1984 * See [StaticWarningCode.ASSIGNMENT_TO_CONST], | 1992 * See [StaticWarningCode.ASSIGNMENT_TO_CONST], |
| (...skipping 1258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3243 // prepare expression type | 3251 // prepare expression type |
| 3244 Expression expression = initializer.expression; | 3252 Expression expression = initializer.expression; |
| 3245 if (expression == null) { | 3253 if (expression == null) { |
| 3246 return false; | 3254 return false; |
| 3247 } | 3255 } |
| 3248 // test the static type of the expression | 3256 // test the static type of the expression |
| 3249 DartType staticType = getStaticType(expression); | 3257 DartType staticType = getStaticType(expression); |
| 3250 if (staticType == null) { | 3258 if (staticType == null) { |
| 3251 return false; | 3259 return false; |
| 3252 } | 3260 } |
| 3253 if (staticType.isAssignableTo(fieldType)) { | 3261 if (_typeSystem.isAssignableTo(staticType, fieldType)) { |
| 3254 return false; | 3262 return false; |
| 3255 } | 3263 } |
| 3256 // report problem | 3264 // report problem |
| 3257 if (_isEnclosingConstructorConst) { | 3265 if (_isEnclosingConstructorConst) { |
| 3258 // TODO(paulberry): this error should be based on the actual type of the | 3266 // TODO(paulberry): this error should be based on the actual type of the |
| 3259 // constant, not the static type. See dartbug.com/21119. | 3267 // constant, not the static type. See dartbug.com/21119. |
| 3260 _errorReporter.reportTypeErrorForNode( | 3268 _errorReporter.reportTypeErrorForNode( |
| 3261 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, | 3269 CheckedModeCompileTimeErrorCode.CONST_FIELD_INITIALIZER_NOT_ASSIGNABLE
, |
| 3262 expression, | 3270 expression, |
| 3263 [staticType, fieldType]); | 3271 [staticType, fieldType]); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3393 * respectively. If not, report the error using [returnType]. | 3401 * respectively. If not, report the error using [returnType]. |
| 3394 */ | 3402 */ |
| 3395 void _checkForIllegalReturnType(TypeName returnType) { | 3403 void _checkForIllegalReturnType(TypeName returnType) { |
| 3396 if (returnType == null) { | 3404 if (returnType == null) { |
| 3397 // No declared return type, so the return type must be dynamic, which is | 3405 // No declared return type, so the return type must be dynamic, which is |
| 3398 // assignable to everything. | 3406 // assignable to everything. |
| 3399 return; | 3407 return; |
| 3400 } | 3408 } |
| 3401 if (_enclosingFunction.isAsynchronous) { | 3409 if (_enclosingFunction.isAsynchronous) { |
| 3402 if (_enclosingFunction.isGenerator) { | 3410 if (_enclosingFunction.isGenerator) { |
| 3403 if (!_enclosingFunction.returnType | 3411 if (!_typeSystem.isAssignableTo( |
| 3404 .isAssignableTo(_typeProvider.streamDynamicType)) { | 3412 _enclosingFunction.returnType, _typeProvider.streamDynamicType)) { |
| 3405 _errorReporter.reportErrorForNode( | 3413 _errorReporter.reportErrorForNode( |
| 3406 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, | 3414 StaticTypeWarningCode.ILLEGAL_ASYNC_GENERATOR_RETURN_TYPE, |
| 3407 returnType); | 3415 returnType); |
| 3408 } | 3416 } |
| 3409 } else { | 3417 } else { |
| 3410 if (!_enclosingFunction.returnType | 3418 if (!_typeSystem.isAssignableTo( |
| 3411 .isAssignableTo(_typeProvider.futureDynamicType)) { | 3419 _enclosingFunction.returnType, _typeProvider.futureDynamicType)) { |
| 3412 _errorReporter.reportErrorForNode( | 3420 _errorReporter.reportErrorForNode( |
| 3413 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, returnType); | 3421 StaticTypeWarningCode.ILLEGAL_ASYNC_RETURN_TYPE, returnType); |
| 3414 } | 3422 } |
| 3415 } | 3423 } |
| 3416 } else if (_enclosingFunction.isGenerator) { | 3424 } else if (_enclosingFunction.isGenerator) { |
| 3417 if (!_enclosingFunction.returnType | 3425 if (!_typeSystem.isAssignableTo( |
| 3418 .isAssignableTo(_typeProvider.iterableDynamicType)) { | 3426 _enclosingFunction.returnType, _typeProvider.iterableDynamicType)) { |
| 3419 _errorReporter.reportErrorForNode( | 3427 _errorReporter.reportErrorForNode( |
| 3420 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, | 3428 StaticTypeWarningCode.ILLEGAL_SYNC_GENERATOR_RETURN_TYPE, |
| 3421 returnType); | 3429 returnType); |
| 3422 } | 3430 } |
| 3423 } | 3431 } |
| 3424 } | 3432 } |
| 3425 | 3433 |
| 3426 /** | 3434 /** |
| 3427 * Verify that the given implements [clause] does not implement classes that | 3435 * Verify that the given implements [clause] does not implement classes that |
| 3428 * are deferred. | 3436 * are deferred. |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3781 */ | 3789 */ |
| 3782 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { | 3790 bool _checkForInvalidAssignment(Expression lhs, Expression rhs) { |
| 3783 if (lhs == null || rhs == null) { | 3791 if (lhs == null || rhs == null) { |
| 3784 return false; | 3792 return false; |
| 3785 } | 3793 } |
| 3786 VariableElement leftVariableElement = getVariableElement(lhs); | 3794 VariableElement leftVariableElement = getVariableElement(lhs); |
| 3787 DartType leftType = (leftVariableElement == null) | 3795 DartType leftType = (leftVariableElement == null) |
| 3788 ? getStaticType(lhs) | 3796 ? getStaticType(lhs) |
| 3789 : leftVariableElement.type; | 3797 : leftVariableElement.type; |
| 3790 DartType staticRightType = getStaticType(rhs); | 3798 DartType staticRightType = getStaticType(rhs); |
| 3791 if (!staticRightType.isAssignableTo(leftType)) { | 3799 if (!_typeSystem.isAssignableTo(staticRightType, leftType)) { |
| 3792 _errorReporter.reportTypeErrorForNode( | 3800 _errorReporter.reportTypeErrorForNode( |
| 3793 StaticTypeWarningCode.INVALID_ASSIGNMENT, | 3801 StaticTypeWarningCode.INVALID_ASSIGNMENT, |
| 3794 rhs, | 3802 rhs, |
| 3795 [staticRightType, leftType]); | 3803 [staticRightType, leftType]); |
| 3796 return true; | 3804 return true; |
| 3797 } | 3805 } |
| 3798 return false; | 3806 return false; |
| 3799 } | 3807 } |
| 3800 | 3808 |
| 3801 /** | 3809 /** |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3815 ? getStaticType(lhs) | 3823 ? getStaticType(lhs) |
| 3816 : leftVariableElement.type; | 3824 : leftVariableElement.type; |
| 3817 MethodElement invokedMethod = assignment.staticElement; | 3825 MethodElement invokedMethod = assignment.staticElement; |
| 3818 if (invokedMethod == null) { | 3826 if (invokedMethod == null) { |
| 3819 return false; | 3827 return false; |
| 3820 } | 3828 } |
| 3821 DartType rightType = invokedMethod.type.returnType; | 3829 DartType rightType = invokedMethod.type.returnType; |
| 3822 if (leftType == null || rightType == null) { | 3830 if (leftType == null || rightType == null) { |
| 3823 return false; | 3831 return false; |
| 3824 } | 3832 } |
| 3825 if (!rightType.isAssignableTo(leftType)) { | 3833 if (!_typeSystem.isAssignableTo(rightType, leftType)) { |
| 3826 _errorReporter.reportTypeErrorForNode( | 3834 _errorReporter.reportTypeErrorForNode( |
| 3827 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType, leftType]); | 3835 StaticTypeWarningCode.INVALID_ASSIGNMENT, rhs, [rightType, leftType]); |
| 3828 return true; | 3836 return true; |
| 3829 } | 3837 } |
| 3830 return false; | 3838 return false; |
| 3831 } | 3839 } |
| 3832 | 3840 |
| 3833 /** | 3841 /** |
| 3834 * Check the given [initializer] to ensure that the field being initialized is | 3842 * Check the given [initializer] to ensure that the field being initialized is |
| 3835 * a valid field. The [fieldName] is the field name from the | 3843 * a valid field. The [fieldName] is the field name from the |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4089 getterType = _getGetterType(propertyAccessorElement); | 4097 getterType = _getGetterType(propertyAccessorElement); |
| 4090 setterType = _getSetterType(counterpartAccessor); | 4098 setterType = _getSetterType(counterpartAccessor); |
| 4091 } else if (propertyAccessorElement.isSetter) { | 4099 } else if (propertyAccessorElement.isSetter) { |
| 4092 setterType = _getSetterType(propertyAccessorElement); | 4100 setterType = _getSetterType(propertyAccessorElement); |
| 4093 getterType = _getGetterType(counterpartAccessor); | 4101 getterType = _getGetterType(counterpartAccessor); |
| 4094 } | 4102 } |
| 4095 // If either types are not assignable to each other, report an error | 4103 // If either types are not assignable to each other, report an error |
| 4096 // (if the getter is null, it is dynamic which is assignable to everything). | 4104 // (if the getter is null, it is dynamic which is assignable to everything). |
| 4097 if (setterType != null && | 4105 if (setterType != null && |
| 4098 getterType != null && | 4106 getterType != null && |
| 4099 !getterType.isAssignableTo(setterType)) { | 4107 !_typeSystem.isAssignableTo(getterType, setterType)) { |
| 4100 if (enclosingClassForCounterpart == null) { | 4108 if (enclosingClassForCounterpart == null) { |
| 4101 _errorReporter.reportTypeErrorForNode( | 4109 _errorReporter.reportTypeErrorForNode( |
| 4102 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, | 4110 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES, |
| 4103 accessorDeclaration, | 4111 accessorDeclaration, |
| 4104 [accessorTextName, setterType, getterType]); | 4112 [accessorTextName, setterType, getterType]); |
| 4105 return true; | 4113 return true; |
| 4106 } else { | 4114 } else { |
| 4107 _errorReporter.reportTypeErrorForNode( | 4115 _errorReporter.reportTypeErrorForNode( |
| 4108 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, | 4116 StaticWarningCode.MISMATCHED_GETTER_AND_SETTER_TYPES_FROM_SUPERTYPE, |
| 4109 accessorDeclaration, [ | 4117 accessorDeclaration, [ |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4487 if ((elt is MethodElement && !elt.isAbstract) || | 4495 if ((elt is MethodElement && !elt.isAbstract) || |
| 4488 (elt is PropertyAccessorElement && !elt.isAbstract)) { | 4496 (elt is PropertyAccessorElement && !elt.isAbstract)) { |
| 4489 // Since we are comparing two function types, we need to do the | 4497 // Since we are comparing two function types, we need to do the |
| 4490 // appropriate type substitutions first (). | 4498 // appropriate type substitutions first (). |
| 4491 FunctionType foundConcreteFT = _inheritanceManager | 4499 FunctionType foundConcreteFT = _inheritanceManager |
| 4492 .substituteTypeArgumentsInMemberFromInheritance( | 4500 .substituteTypeArgumentsInMemberFromInheritance( |
| 4493 concreteType, memberName, enclosingType); | 4501 concreteType, memberName, enclosingType); |
| 4494 FunctionType requiredMemberFT = _inheritanceManager | 4502 FunctionType requiredMemberFT = _inheritanceManager |
| 4495 .substituteTypeArgumentsInMemberFromInheritance( | 4503 .substituteTypeArgumentsInMemberFromInheritance( |
| 4496 requiredMemberType, memberName, enclosingType); | 4504 requiredMemberType, memberName, enclosingType); |
| 4497 if (foundConcreteFT.isSubtypeOf(requiredMemberFT)) { | 4505 if (_typeSystem.isSubtypeOf(foundConcreteFT, requiredMemberFT)) { |
| 4498 continue; | 4506 continue; |
| 4499 } | 4507 } |
| 4500 } | 4508 } |
| 4501 } | 4509 } |
| 4502 // The not qualifying concrete executable element was found, add it to the | 4510 // The not qualifying concrete executable element was found, add it to the |
| 4503 // list. | 4511 // list. |
| 4504 missingOverrides.add(executableElt); | 4512 missingOverrides.add(executableElt); |
| 4505 } | 4513 } |
| 4506 // Now that we have the set of missing overrides, generate a warning on this | 4514 // Now that we have the set of missing overrides, generate a warning on this |
| 4507 // class. | 4515 // class. |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4582 } | 4590 } |
| 4583 | 4591 |
| 4584 /** | 4592 /** |
| 4585 * Check to ensure that the [condition] is of type bool, are. Otherwise an | 4593 * Check to ensure that the [condition] is of type bool, are. Otherwise an |
| 4586 * error is reported on the expression. | 4594 * error is reported on the expression. |
| 4587 * | 4595 * |
| 4588 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. | 4596 * See [StaticTypeWarningCode.NON_BOOL_CONDITION]. |
| 4589 */ | 4597 */ |
| 4590 bool _checkForNonBoolCondition(Expression condition) { | 4598 bool _checkForNonBoolCondition(Expression condition) { |
| 4591 DartType conditionType = getStaticType(condition); | 4599 DartType conditionType = getStaticType(condition); |
| 4592 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4600 if (conditionType != null && |
| 4601 !_typeSystem.isAssignableTo(conditionType, _boolType)) { |
| 4593 _errorReporter.reportErrorForNode( | 4602 _errorReporter.reportErrorForNode( |
| 4594 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); | 4603 StaticTypeWarningCode.NON_BOOL_CONDITION, condition); |
| 4595 return true; | 4604 return true; |
| 4596 } | 4605 } |
| 4597 return false; | 4606 return false; |
| 4598 } | 4607 } |
| 4599 | 4608 |
| 4600 /** | 4609 /** |
| 4601 * Verify that the given assert [statement] has either a 'bool' or | 4610 * Verify that the given assert [statement] has either a 'bool' or |
| 4602 * '() -> bool' input. | 4611 * '() -> bool' input. |
| 4603 * | 4612 * |
| 4604 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. | 4613 * See [StaticTypeWarningCode.NON_BOOL_EXPRESSION]. |
| 4605 */ | 4614 */ |
| 4606 bool _checkForNonBoolExpression(AssertStatement statement) { | 4615 bool _checkForNonBoolExpression(AssertStatement statement) { |
| 4607 Expression expression = statement.condition; | 4616 Expression expression = statement.condition; |
| 4608 DartType type = getStaticType(expression); | 4617 DartType type = getStaticType(expression); |
| 4609 if (type is InterfaceType) { | 4618 if (type is InterfaceType) { |
| 4610 if (!type.isAssignableTo(_boolType)) { | 4619 if (!_typeSystem.isAssignableTo(type, _boolType)) { |
| 4611 _errorReporter.reportErrorForNode( | 4620 _errorReporter.reportErrorForNode( |
| 4612 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4621 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 4613 return true; | 4622 return true; |
| 4614 } | 4623 } |
| 4615 } else if (type is FunctionType) { | 4624 } else if (type is FunctionType) { |
| 4616 FunctionType functionType = type; | 4625 FunctionType functionType = type; |
| 4617 if (functionType.typeArguments.length == 0 && | 4626 if (functionType.typeArguments.length == 0 && |
| 4618 !functionType.returnType.isAssignableTo(_boolType)) { | 4627 !_typeSystem.isAssignableTo(functionType.returnType, _boolType)) { |
| 4619 _errorReporter.reportErrorForNode( | 4628 _errorReporter.reportErrorForNode( |
| 4620 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); | 4629 StaticTypeWarningCode.NON_BOOL_EXPRESSION, expression); |
| 4621 return true; | 4630 return true; |
| 4622 } | 4631 } |
| 4623 } | 4632 } |
| 4624 return false; | 4633 return false; |
| 4625 } | 4634 } |
| 4626 | 4635 |
| 4627 /** | 4636 /** |
| 4628 * Checks to ensure that the given [expression] is assignable to bool. | 4637 * Checks to ensure that the given [expression] is assignable to bool. |
| 4629 * | 4638 * |
| 4630 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. | 4639 * See [StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION]. |
| 4631 */ | 4640 */ |
| 4632 bool _checkForNonBoolNegationExpression(Expression expression) { | 4641 bool _checkForNonBoolNegationExpression(Expression expression) { |
| 4633 DartType conditionType = getStaticType(expression); | 4642 DartType conditionType = getStaticType(expression); |
| 4634 if (conditionType != null && !conditionType.isAssignableTo(_boolType)) { | 4643 if (conditionType != null && |
| 4644 !_typeSystem.isAssignableTo(conditionType, _boolType)) { |
| 4635 _errorReporter.reportErrorForNode( | 4645 _errorReporter.reportErrorForNode( |
| 4636 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, expression); | 4646 StaticTypeWarningCode.NON_BOOL_NEGATION_EXPRESSION, expression); |
| 4637 return true; | 4647 return true; |
| 4638 } | 4648 } |
| 4639 return false; | 4649 return false; |
| 4640 } | 4650 } |
| 4641 | 4651 |
| 4642 /** | 4652 /** |
| 4643 * Verify the given map [literal] either: | 4653 * Verify the given map [literal] either: |
| 4644 * * has `const modifier` | 4654 * * has `const modifier` |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5020 return false; | 5030 return false; |
| 5021 } | 5031 } |
| 5022 _errorReporter.reportTypeErrorForNode( | 5032 _errorReporter.reportTypeErrorForNode( |
| 5023 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ | 5033 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, returnExpression, [ |
| 5024 staticReturnType, | 5034 staticReturnType, |
| 5025 expectedReturnType, | 5035 expectedReturnType, |
| 5026 _enclosingFunction.displayName | 5036 _enclosingFunction.displayName |
| 5027 ]); | 5037 ]); |
| 5028 return true; | 5038 return true; |
| 5029 } | 5039 } |
| 5030 if (staticReturnType.isAssignableTo(expectedReturnType)) { | 5040 if (_typeSystem.isAssignableTo(staticReturnType, expectedReturnType)) { |
| 5031 return false; | 5041 return false; |
| 5032 } | 5042 } |
| 5033 _errorReporter.reportTypeErrorForNode( | 5043 _errorReporter.reportTypeErrorForNode( |
| 5034 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, | 5044 StaticTypeWarningCode.RETURN_OF_INVALID_TYPE, |
| 5035 returnExpression, | 5045 returnExpression, |
| 5036 [staticReturnType, expectedReturnType, _enclosingFunction.displayName]); | 5046 [staticReturnType, expectedReturnType, _enclosingFunction.displayName]); |
| 5037 return true; | 5047 return true; |
| 5038 // TODO(brianwilkerson) Define a hint corresponding to the warning and | 5048 // TODO(brianwilkerson) Define a hint corresponding to the warning and |
| 5039 // report it if appropriate. | 5049 // report it if appropriate. |
| 5040 // Type propagatedReturnType = returnExpression.getPropagatedType(); | 5050 // Type propagatedReturnType = returnExpression.getPropagatedType(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5096 NodeList<SwitchMember> members = statement.members; | 5106 NodeList<SwitchMember> members = statement.members; |
| 5097 for (SwitchMember switchMember in members) { | 5107 for (SwitchMember switchMember in members) { |
| 5098 if (switchMember is! SwitchCase) { | 5108 if (switchMember is! SwitchCase) { |
| 5099 continue; | 5109 continue; |
| 5100 } | 5110 } |
| 5101 SwitchCase switchCase = switchMember as SwitchCase; | 5111 SwitchCase switchCase = switchMember as SwitchCase; |
| 5102 // prepare 'case' type | 5112 // prepare 'case' type |
| 5103 Expression caseExpression = switchCase.expression; | 5113 Expression caseExpression = switchCase.expression; |
| 5104 DartType caseType = getStaticType(caseExpression); | 5114 DartType caseType = getStaticType(caseExpression); |
| 5105 // check types | 5115 // check types |
| 5106 if (expressionType.isAssignableTo(caseType)) { | 5116 if (_typeSystem.isAssignableTo(expressionType, caseType)) { |
| 5107 return false; | 5117 return false; |
| 5108 } | 5118 } |
| 5109 // report problem | 5119 // report problem |
| 5110 _errorReporter.reportErrorForNode( | 5120 _errorReporter.reportErrorForNode( |
| 5111 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, | 5121 StaticWarningCode.SWITCH_EXPRESSION_NOT_ASSIGNABLE, |
| 5112 expression, | 5122 expression, |
| 5113 [expressionType, caseType]); | 5123 [expressionType, caseType]); |
| 5114 return true; | 5124 return true; |
| 5115 } | 5125 } |
| 5116 return false; | 5126 return false; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5178 bool foundError = false; | 5188 bool foundError = false; |
| 5179 for (int i = 0; i < loopThroughIndex; i++) { | 5189 for (int i = 0; i < loopThroughIndex; i++) { |
| 5180 TypeName argTypeName = typeNameArgList[i]; | 5190 TypeName argTypeName = typeNameArgList[i]; |
| 5181 DartType argType = argTypeName.type; | 5191 DartType argType = argTypeName.type; |
| 5182 DartType boundType = boundingElts[i].bound; | 5192 DartType boundType = boundingElts[i].bound; |
| 5183 if (argType != null && boundType != null) { | 5193 if (argType != null && boundType != null) { |
| 5184 if (typeArguments.length != 0 && | 5194 if (typeArguments.length != 0 && |
| 5185 typeArguments.length == typeParameters.length) { | 5195 typeArguments.length == typeParameters.length) { |
| 5186 boundType = boundType.substitute2(typeArguments, typeParameters); | 5196 boundType = boundType.substitute2(typeArguments, typeParameters); |
| 5187 } | 5197 } |
| 5188 if (!argType.isSubtypeOf(boundType)) { | 5198 if (!_typeSystem.isSubtypeOf(argType, boundType)) { |
| 5189 ErrorCode errorCode; | 5199 ErrorCode errorCode; |
| 5190 if (_isInConstInstanceCreation) { | 5200 if (_isInConstInstanceCreation) { |
| 5191 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | 5201 errorCode = CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; |
| 5192 } else { | 5202 } else { |
| 5193 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; | 5203 errorCode = StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; |
| 5194 } | 5204 } |
| 5195 _errorReporter.reportTypeErrorForNode( | 5205 _errorReporter.reportTypeErrorForNode( |
| 5196 errorCode, argTypeName, [argType, boundType]); | 5206 errorCode, argTypeName, [argType, boundType]); |
| 5197 foundError = true; | 5207 foundError = true; |
| 5198 } | 5208 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5374 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5384 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5375 parameter, | 5385 parameter, |
| 5376 [parameter.identifier.name]); | 5386 [parameter.identifier.name]); |
| 5377 } else if (fieldElement.isStatic) { | 5387 } else if (fieldElement.isStatic) { |
| 5378 _errorReporter.reportErrorForNode( | 5388 _errorReporter.reportErrorForNode( |
| 5379 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, | 5389 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_STATIC_FIELD, |
| 5380 parameter, | 5390 parameter, |
| 5381 [parameter.identifier.name]); | 5391 [parameter.identifier.name]); |
| 5382 } else if (declaredType != null && | 5392 } else if (declaredType != null && |
| 5383 fieldType != null && | 5393 fieldType != null && |
| 5384 !declaredType.isAssignableTo(fieldType)) { | 5394 !_typeSystem.isAssignableTo(declaredType, fieldType)) { |
| 5385 _errorReporter.reportTypeErrorForNode( | 5395 _errorReporter.reportTypeErrorForNode( |
| 5386 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, | 5396 StaticWarningCode.FIELD_INITIALIZING_FORMAL_NOT_ASSIGNABLE, |
| 5387 parameter, | 5397 parameter, |
| 5388 [declaredType, fieldType]); | 5398 [declaredType, fieldType]); |
| 5389 } | 5399 } |
| 5390 } else { | 5400 } else { |
| 5391 if (fieldElement.isSynthetic) { | 5401 if (fieldElement.isSynthetic) { |
| 5392 _errorReporter.reportErrorForNode( | 5402 _errorReporter.reportErrorForNode( |
| 5393 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, | 5403 CompileTimeErrorCode.INITIALIZING_FORMAL_FOR_NON_EXISTENT_FIELD, |
| 5394 parameter, | 5404 parameter, |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5535 DartType impliedReturnType; | 5545 DartType impliedReturnType; |
| 5536 if (isYieldEach) { | 5546 if (isYieldEach) { |
| 5537 impliedReturnType = staticYieldedType; | 5547 impliedReturnType = staticYieldedType; |
| 5538 } else if (_enclosingFunction.isAsynchronous) { | 5548 } else if (_enclosingFunction.isAsynchronous) { |
| 5539 impliedReturnType = | 5549 impliedReturnType = |
| 5540 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); | 5550 _typeProvider.streamType.substitute4(<DartType>[staticYieldedType]); |
| 5541 } else { | 5551 } else { |
| 5542 impliedReturnType = | 5552 impliedReturnType = |
| 5543 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); | 5553 _typeProvider.iterableType.substitute4(<DartType>[staticYieldedType]); |
| 5544 } | 5554 } |
| 5545 if (!impliedReturnType.isAssignableTo(declaredReturnType)) { | 5555 if (!_typeSystem.isAssignableTo(impliedReturnType, declaredReturnType)) { |
| 5546 _errorReporter.reportTypeErrorForNode( | 5556 _errorReporter.reportTypeErrorForNode( |
| 5547 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 5557 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
| 5548 yieldExpression, | 5558 yieldExpression, |
| 5549 [impliedReturnType, declaredReturnType]); | 5559 [impliedReturnType, declaredReturnType]); |
| 5550 return true; | 5560 return true; |
| 5551 } | 5561 } |
| 5552 if (isYieldEach) { | 5562 if (isYieldEach) { |
| 5553 // Since the declared return type might have been "dynamic", we need to | 5563 // Since the declared return type might have been "dynamic", we need to |
| 5554 // also check that the implied return type is assignable to generic | 5564 // also check that the implied return type is assignable to generic |
| 5555 // Stream/Iterable. | 5565 // Stream/Iterable. |
| 5556 DartType requiredReturnType; | 5566 DartType requiredReturnType; |
| 5557 if (_enclosingFunction.isAsynchronous) { | 5567 if (_enclosingFunction.isAsynchronous) { |
| 5558 requiredReturnType = _typeProvider.streamDynamicType; | 5568 requiredReturnType = _typeProvider.streamDynamicType; |
| 5559 } else { | 5569 } else { |
| 5560 requiredReturnType = _typeProvider.iterableDynamicType; | 5570 requiredReturnType = _typeProvider.iterableDynamicType; |
| 5561 } | 5571 } |
| 5562 if (!impliedReturnType.isAssignableTo(requiredReturnType)) { | 5572 if (!_typeSystem.isAssignableTo(impliedReturnType, requiredReturnType)) { |
| 5563 _errorReporter.reportTypeErrorForNode( | 5573 _errorReporter.reportTypeErrorForNode( |
| 5564 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, | 5574 StaticTypeWarningCode.YIELD_OF_INVALID_TYPE, |
| 5565 yieldExpression, | 5575 yieldExpression, |
| 5566 [impliedReturnType, requiredReturnType]); | 5576 [impliedReturnType, requiredReturnType]); |
| 5567 return true; | 5577 return true; |
| 5568 } | 5578 } |
| 5569 } | 5579 } |
| 5570 return false; | 5580 return false; |
| 5571 } | 5581 } |
| 5572 | 5582 |
| 5573 /** | 5583 /** |
| 5574 * Verify that if the given class [declaration] implements the class Function | 5584 * Verify that if the given class [declaration] implements the class Function |
| 5575 * that it has a concrete implementation of the call method. | 5585 * that it has a concrete implementation of the call method. |
| 5576 * | 5586 * |
| 5577 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. | 5587 * See [StaticWarningCode.FUNCTION_WITHOUT_CALL]. |
| 5578 */ | 5588 */ |
| 5579 bool _checkImplementsFunctionWithoutCall(ClassDeclaration declaration) { | 5589 bool _checkImplementsFunctionWithoutCall(ClassDeclaration declaration) { |
| 5580 if (declaration.isAbstract) { | 5590 if (declaration.isAbstract) { |
| 5581 return false; | 5591 return false; |
| 5582 } | 5592 } |
| 5583 ClassElement classElement = declaration.element; | 5593 ClassElement classElement = declaration.element; |
| 5584 if (classElement == null) { | 5594 if (classElement == null) { |
| 5585 return false; | 5595 return false; |
| 5586 } | 5596 } |
| 5587 if (!classElement.type.isSubtypeOf(_typeProvider.functionType)) { | 5597 if (!_typeSystem.isSubtypeOf( |
| 5598 classElement.type, _typeProvider.functionType)) { |
| 5588 return false; | 5599 return false; |
| 5589 } | 5600 } |
| 5590 // If there is a noSuchMethod method, then don't report the warning, | 5601 // If there is a noSuchMethod method, then don't report the warning, |
| 5591 // see dartbug.com/16078 | 5602 // see dartbug.com/16078 |
| 5592 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != | 5603 if (classElement.getMethod(FunctionElement.NO_SUCH_METHOD_METHOD_NAME) != |
| 5593 null) { | 5604 null) { |
| 5594 return false; | 5605 return false; |
| 5595 } | 5606 } |
| 5596 ExecutableElement callMethod = _inheritanceManager.lookupMember( | 5607 ExecutableElement callMethod = _inheritanceManager.lookupMember( |
| 5597 classElement, FunctionElement.CALL_METHOD_NAME); | 5608 classElement, FunctionElement.CALL_METHOD_NAME); |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6060 toCheck.add(type.element); | 6071 toCheck.add(type.element); |
| 6061 // type arguments | 6072 // type arguments |
| 6062 if (type is InterfaceType) { | 6073 if (type is InterfaceType) { |
| 6063 InterfaceType interfaceType = type; | 6074 InterfaceType interfaceType = type; |
| 6064 for (DartType typeArgument in interfaceType.typeArguments) { | 6075 for (DartType typeArgument in interfaceType.typeArguments) { |
| 6065 _addTypeToCheck(typeArgument); | 6076 _addTypeToCheck(typeArgument); |
| 6066 } | 6077 } |
| 6067 } | 6078 } |
| 6068 } | 6079 } |
| 6069 } | 6080 } |
| OLD | NEW |