| 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 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 } | 779 } |
| 780 _checkForNonVoidReturnTypeForSetter(returnType); | 780 _checkForNonVoidReturnTypeForSetter(returnType); |
| 781 } | 781 } |
| 782 } | 782 } |
| 783 if (node.isSetter) { | 783 if (node.isSetter) { |
| 784 _checkForInvalidModifierOnBody(node.functionExpression.body, | 784 _checkForInvalidModifierOnBody(node.functionExpression.body, |
| 785 CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER); | 785 CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER); |
| 786 } | 786 } |
| 787 _checkForTypeAnnotationDeferredClass(returnType); | 787 _checkForTypeAnnotationDeferredClass(returnType); |
| 788 _checkForIllegalReturnType(returnType); | 788 _checkForIllegalReturnType(returnType); |
| 789 _checkForImplicitDynamicReturn(node, node.element); | 789 _checkForImplicitDynamicReturn(node.name, node.element); |
| 790 return super.visitFunctionDeclaration(node); | 790 return super.visitFunctionDeclaration(node); |
| 791 } finally { | 791 } finally { |
| 792 _enclosingFunction = outerFunction; | 792 _enclosingFunction = outerFunction; |
| 793 } | 793 } |
| 794 } | 794 } |
| 795 | 795 |
| 796 @override | 796 @override |
| 797 Object visitFunctionExpression(FunctionExpression node) { | 797 Object visitFunctionExpression(FunctionExpression node) { |
| 798 // If this function expression is wrapped in a function declaration, don't | 798 // If this function expression is wrapped in a function declaration, don't |
| 799 // change the enclosingFunction field. | 799 // change the enclosingFunction field. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 | 843 |
| 844 // TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and | 844 // TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and |
| 845 // we can get the function element via `node?.element?.type?.element` but | 845 // we can get the function element via `node?.element?.type?.element` but |
| 846 // it doesn't have hasImplicitReturnType set correctly. | 846 // it doesn't have hasImplicitReturnType set correctly. |
| 847 if (!_options.implicitDynamic && node.returnType == null) { | 847 if (!_options.implicitDynamic && node.returnType == null) { |
| 848 DartType parameterType = | 848 DartType parameterType = |
| 849 resolutionMap.elementDeclaredByFormalParameter(node).type; | 849 resolutionMap.elementDeclaredByFormalParameter(node).type; |
| 850 if (parameterType is FunctionType && | 850 if (parameterType is FunctionType && |
| 851 parameterType.returnType.isDynamic) { | 851 parameterType.returnType.isDynamic) { |
| 852 _errorReporter.reportErrorForNode( | 852 _errorReporter.reportErrorForNode( |
| 853 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [node.identifier]); | 853 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, |
| 854 node.identifier, |
| 855 [node.identifier]); |
| 854 } | 856 } |
| 855 } | 857 } |
| 856 return super.visitFunctionTypedFormalParameter(node); | 858 return super.visitFunctionTypedFormalParameter(node); |
| 857 } finally { | 859 } finally { |
| 858 _isInFunctionTypedFormalParameter = old; | 860 _isInFunctionTypedFormalParameter = old; |
| 859 } | 861 } |
| 860 } | 862 } |
| 861 | 863 |
| 862 @override | 864 @override |
| 863 Object visitIfStatement(IfStatement node) { | 865 Object visitIfStatement(IfStatement node) { |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 _checkForConflictingStaticSetterAndInstanceMember(node); | 989 _checkForConflictingStaticSetterAndInstanceMember(node); |
| 988 } else if (node.isOperator) { | 990 } else if (node.isOperator) { |
| 989 _checkForOptionalParameterInOperator(node); | 991 _checkForOptionalParameterInOperator(node); |
| 990 _checkForWrongNumberOfParametersForOperator(node); | 992 _checkForWrongNumberOfParametersForOperator(node); |
| 991 _checkForNonVoidReturnTypeForOperator(node); | 993 _checkForNonVoidReturnTypeForOperator(node); |
| 992 } | 994 } |
| 993 _checkForConcreteClassWithAbstractMember(node); | 995 _checkForConcreteClassWithAbstractMember(node); |
| 994 _checkForAllInvalidOverrideErrorCodesForMethod(node); | 996 _checkForAllInvalidOverrideErrorCodesForMethod(node); |
| 995 _checkForTypeAnnotationDeferredClass(returnTypeName); | 997 _checkForTypeAnnotationDeferredClass(returnTypeName); |
| 996 _checkForIllegalReturnType(returnTypeName); | 998 _checkForIllegalReturnType(returnTypeName); |
| 997 _checkForImplicitDynamicReturn(node, node.element); | 999 _checkForImplicitDynamicReturn(node.name, node.element); |
| 998 _checkForMustCallSuper(node); | 1000 _checkForMustCallSuper(node); |
| 999 return super.visitMethodDeclaration(node); | 1001 return super.visitMethodDeclaration(node); |
| 1000 } finally { | 1002 } finally { |
| 1001 _enclosingFunction = previousFunction; | 1003 _enclosingFunction = previousFunction; |
| 1002 _isInStaticMethod = false; | 1004 _isInStaticMethod = false; |
| 1003 } | 1005 } |
| 1004 } | 1006 } |
| 1005 | 1007 |
| 1006 @override | 1008 @override |
| 1007 Object visitMethodInvocation(MethodInvocation node) { | 1009 Object visitMethodInvocation(MethodInvocation node) { |
| (...skipping 2957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3965 // The catch all case if neither of those matched. | 3967 // The catch all case if neither of those matched. |
| 3966 // For example, invoking a function expression. | 3968 // For example, invoking a function expression. |
| 3967 _errorReporter.reportErrorForNode( | 3969 _errorReporter.reportErrorForNode( |
| 3968 StrongModeCode.IMPLICIT_DYNAMIC_INVOKE, | 3970 StrongModeCode.IMPLICIT_DYNAMIC_INVOKE, |
| 3969 node.function, | 3971 node.function, |
| 3970 [declaredType]); | 3972 [declaredType]); |
| 3971 } | 3973 } |
| 3972 } | 3974 } |
| 3973 } | 3975 } |
| 3974 | 3976 |
| 3975 void _checkForImplicitDynamicReturn(AstNode node, ExecutableElement element) { | 3977 void _checkForImplicitDynamicReturn( |
| 3978 AstNode functionName, ExecutableElement element) { |
| 3976 if (_options.implicitDynamic) { | 3979 if (_options.implicitDynamic) { |
| 3977 return; | 3980 return; |
| 3978 } | 3981 } |
| 3979 if (element is PropertyAccessorElement && element.isSetter) { | 3982 if (element is PropertyAccessorElement && element.isSetter) { |
| 3980 return; | 3983 return; |
| 3981 } | 3984 } |
| 3982 if (element != null && | 3985 if (element != null && |
| 3983 element.hasImplicitReturnType && | 3986 element.hasImplicitReturnType && |
| 3984 element.returnType.isDynamic) { | 3987 element.returnType.isDynamic) { |
| 3985 _errorReporter.reportErrorForNode( | 3988 _errorReporter.reportErrorForNode(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, |
| 3986 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [element.displayName]); | 3989 functionName, [element.displayName]); |
| 3987 } | 3990 } |
| 3988 } | 3991 } |
| 3989 | 3992 |
| 3990 void _checkForImplicitDynamicType(TypeName node) { | 3993 void _checkForImplicitDynamicType(TypeName node) { |
| 3991 if (_options.implicitDynamic || | 3994 if (_options.implicitDynamic || |
| 3992 node == null || | 3995 node == null || |
| 3993 node.typeArguments != null) { | 3996 node.typeArguments != null) { |
| 3994 return; | 3997 return; |
| 3995 } | 3998 } |
| 3996 DartType type = node.type; | 3999 DartType type = node.type; |
| (...skipping 2958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6955 class _InvocationCollector extends RecursiveAstVisitor { | 6958 class _InvocationCollector extends RecursiveAstVisitor { |
| 6956 final List<String> superCalls = <String>[]; | 6959 final List<String> superCalls = <String>[]; |
| 6957 | 6960 |
| 6958 @override | 6961 @override |
| 6959 visitMethodInvocation(MethodInvocation node) { | 6962 visitMethodInvocation(MethodInvocation node) { |
| 6960 if (node.target is SuperExpression) { | 6963 if (node.target is SuperExpression) { |
| 6961 superCalls.add(node.methodName.name); | 6964 superCalls.add(node.methodName.name); |
| 6962 } | 6965 } |
| 6963 } | 6966 } |
| 6964 } | 6967 } |
| OLD | NEW |