| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.src.generated.error_verifier; | 5 library analyzer.src.generated.error_verifier; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import "dart:math" as math; | 8 import "dart:math" as math; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| (...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 DartType parameterType = | 850 DartType parameterType = |
| 851 resolutionMap.elementDeclaredByFormalParameter(node).type; | 851 resolutionMap.elementDeclaredByFormalParameter(node).type; |
| 852 if (parameterType is FunctionType && | 852 if (parameterType is FunctionType && |
| 853 parameterType.returnType.isDynamic) { | 853 parameterType.returnType.isDynamic) { |
| 854 _errorReporter.reportErrorForNode( | 854 _errorReporter.reportErrorForNode( |
| 855 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, | 855 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, |
| 856 node.identifier, | 856 node.identifier, |
| 857 [node.identifier]); | 857 [node.identifier]); |
| 858 } | 858 } |
| 859 } | 859 } |
| 860 |
| 861 // TODO(paulberry): remove this once dartbug.com/28515 is fixed. |
| 862 if (node.typeParameters != null) { |
| 863 _errorReporter.reportErrorForNode( |
| 864 CompileTimeErrorCode.GENERIC_FUNCTION_TYPED_PARAM_UNSUPPORTED, |
| 865 node); |
| 866 } |
| 867 |
| 860 return super.visitFunctionTypedFormalParameter(node); | 868 return super.visitFunctionTypedFormalParameter(node); |
| 861 } finally { | 869 } finally { |
| 862 _isInFunctionTypedFormalParameter = old; | 870 _isInFunctionTypedFormalParameter = old; |
| 863 } | 871 } |
| 864 } | 872 } |
| 865 | 873 |
| 866 @override | 874 @override |
| 867 Object visitGenericFunctionType(GenericFunctionType node) { | 875 Object visitGenericFunctionType(GenericFunctionType node) { |
| 868 throw new StateError( | 876 throw new StateError( |
| 869 'Support for generic function types is not yet implemented'); | 877 'Support for generic function types is not yet implemented'); |
| (...skipping 1696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2566 StaticWarningCode.ASSIGNMENT_TO_METHOD, expression); | 2574 StaticWarningCode.ASSIGNMENT_TO_METHOD, expression); |
| 2567 } else if (element is ClassElement || | 2575 } else if (element is ClassElement || |
| 2568 element is FunctionTypeAliasElement || | 2576 element is FunctionTypeAliasElement || |
| 2569 element is TypeParameterElement) { | 2577 element is TypeParameterElement) { |
| 2570 _errorReporter.reportErrorForNode( | 2578 _errorReporter.reportErrorForNode( |
| 2571 StaticWarningCode.ASSIGNMENT_TO_TYPE, expression); | 2579 StaticWarningCode.ASSIGNMENT_TO_TYPE, expression); |
| 2572 } | 2580 } |
| 2573 } | 2581 } |
| 2574 | 2582 |
| 2575 /** | 2583 /** |
| 2584 * Verifies that the class is not named `Function` and that it doesn't |
| 2585 * extends/implements/mixes in `Function`. |
| 2586 */ |
| 2587 void _checkForBadFunctionUse(ClassDeclaration node) { |
| 2588 ExtendsClause extendsClause = node.extendsClause; |
| 2589 ImplementsClause implementsClause = node.implementsClause; |
| 2590 WithClause withClause = node.withClause; |
| 2591 |
| 2592 if (node.name.name == "Function") { |
| 2593 _errorReporter.reportErrorForNode( |
| 2594 HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, node.name); |
| 2595 } |
| 2596 |
| 2597 if (extendsClause != null) { |
| 2598 InterfaceType superclassType = _enclosingClass.supertype; |
| 2599 ClassElement superclassElement = superclassType?.element; |
| 2600 if (superclassElement != null && superclassElement.name == "Function") { |
| 2601 _errorReporter.reportErrorForNode( |
| 2602 HintCode.DEPRECATED_EXTENDS_FUNCTION, extendsClause.superclass); |
| 2603 } |
| 2604 } |
| 2605 |
| 2606 if (withClause != null) { |
| 2607 for (TypeName type in withClause.mixinTypes) { |
| 2608 Element mixinElement = type.name.staticElement; |
| 2609 if (mixinElement != null && mixinElement.name == "Function") { |
| 2610 _errorReporter.reportErrorForNode( |
| 2611 HintCode.DEPRECATED_MIXIN_FUNCTION, type); |
| 2612 } |
| 2613 } |
| 2614 } |
| 2615 } |
| 2616 |
| 2617 /** |
| 2576 * Verify that the given [identifier] is not a keyword, and generates the | 2618 * Verify that the given [identifier] is not a keyword, and generates the |
| 2577 * given [errorCode] on the identifier if it is a keyword. | 2619 * given [errorCode] on the identifier if it is a keyword. |
| 2578 * | 2620 * |
| 2579 * See [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME], | 2621 * See [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_NAME], |
| 2580 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME], and | 2622 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME], and |
| 2581 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]. | 2623 * [CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME]. |
| 2582 */ | 2624 */ |
| 2583 void _checkForBuiltInIdentifierAsName( | 2625 void _checkForBuiltInIdentifierAsName( |
| 2584 SimpleIdentifier identifier, ErrorCode errorCode) { | 2626 SimpleIdentifier identifier, ErrorCode errorCode) { |
| 2585 Token token = identifier.token; | 2627 Token token = identifier.token; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2936 memberHashMap["${name.name}="] = member; | 2978 memberHashMap["${name.name}="] = member; |
| 2937 } else { | 2979 } else { |
| 2938 memberHashMap[name.name] = member; | 2980 memberHashMap[name.name] = member; |
| 2939 } | 2981 } |
| 2940 } | 2982 } |
| 2941 } | 2983 } |
| 2942 } | 2984 } |
| 2943 } | 2985 } |
| 2944 | 2986 |
| 2945 /** | 2987 /** |
| 2946 * Verifies that the class is not named `Function` and that it doesn't | |
| 2947 * extends/implements/mixes in `Function`. | |
| 2948 */ | |
| 2949 void _checkForBadFunctionUse(ClassDeclaration node) { | |
| 2950 ExtendsClause extendsClause = node.extendsClause; | |
| 2951 ImplementsClause implementsClause = node.implementsClause; | |
| 2952 WithClause withClause = node.withClause; | |
| 2953 | |
| 2954 if (node.name.name == "Function") { | |
| 2955 _errorReporter.reportErrorForNode( | |
| 2956 HintCode.DEPRECATED_FUNCTION_CLASS_DECLARATION, node.name); | |
| 2957 } | |
| 2958 | |
| 2959 if (extendsClause != null) { | |
| 2960 InterfaceType superclassType = _enclosingClass.supertype; | |
| 2961 ClassElement superclassElement = superclassType?.element; | |
| 2962 if (superclassElement != null && superclassElement.name == "Function") { | |
| 2963 _errorReporter.reportErrorForNode( | |
| 2964 HintCode.DEPRECATED_EXTENDS_FUNCTION, extendsClause.superclass); | |
| 2965 } | |
| 2966 } | |
| 2967 | |
| 2968 if (withClause != null) { | |
| 2969 for (TypeName type in withClause.mixinTypes) { | |
| 2970 Element mixinElement = type.name.staticElement; | |
| 2971 if (mixinElement != null && mixinElement.name == "Function") { | |
| 2972 _errorReporter.reportErrorForNode( | |
| 2973 HintCode.DEPRECATED_MIXIN_FUNCTION, type); | |
| 2974 } | |
| 2975 } | |
| 2976 } | |
| 2977 } | |
| 2978 | |
| 2979 /** | |
| 2980 * Verify that the enclosing class does not have an instance member with the | 2988 * Verify that the enclosing class does not have an instance member with the |
| 2981 * same name as the given static [method] declaration. | 2989 * same name as the given static [method] declaration. |
| 2982 * | 2990 * |
| 2983 * See [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]. | 2991 * See [StaticWarningCode.CONFLICTING_STATIC_GETTER_AND_INSTANCE_SETTER]. |
| 2984 */ | 2992 */ |
| 2985 void _checkForConflictingStaticGetterAndInstanceSetter( | 2993 void _checkForConflictingStaticGetterAndInstanceSetter( |
| 2986 MethodDeclaration method) { | 2994 MethodDeclaration method) { |
| 2987 if (!method.isStatic) { | 2995 if (!method.isStatic) { |
| 2988 return; | 2996 return; |
| 2989 } | 2997 } |
| (...skipping 4069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7059 class _InvocationCollector extends RecursiveAstVisitor { | 7067 class _InvocationCollector extends RecursiveAstVisitor { |
| 7060 final List<String> superCalls = <String>[]; | 7068 final List<String> superCalls = <String>[]; |
| 7061 | 7069 |
| 7062 @override | 7070 @override |
| 7063 visitMethodInvocation(MethodInvocation node) { | 7071 visitMethodInvocation(MethodInvocation node) { |
| 7064 if (node.target is SuperExpression) { | 7072 if (node.target is SuperExpression) { |
| 7065 superCalls.add(node.methodName.name); | 7073 superCalls.add(node.methodName.name); |
| 7066 } | 7074 } |
| 7067 } | 7075 } |
| 7068 } | 7076 } |
| OLD | NEW |