Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2093523002: fix #25573, add option to disable implicit dynamic (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Merge remote-tracking branch 'origin/master' into no_implicit_dynamic Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 InterfaceType _boolType; 72 InterfaceType _boolType;
73 73
74 /** 74 /**
75 * The type representing the type 'int'. 75 * The type representing the type 'int'.
76 */ 76 */
77 InterfaceType _intType; 77 InterfaceType _intType;
78 78
79 /** 79 /**
80 * The options for verification. 80 * The options for verification.
81 */ 81 */
82 AnalysisOptions _options; 82 AnalysisOptionsImpl _options;
83 83
84 /** 84 /**
85 * The object providing access to the types defined by the language. 85 * The object providing access to the types defined by the language.
86 */ 86 */
87 final TypeProvider _typeProvider; 87 final TypeProvider _typeProvider;
88 88
89 /** 89 /**
90 * The type system primitives 90 * The type system primitives
91 */ 91 */
92 TypeSystem _typeSystem; 92 TypeSystem _typeSystem;
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 _checkForReturnOfInvalidType(node.expression, expectedReturnType); 669 _checkForReturnOfInvalidType(node.expression, expectedReturnType);
670 } 670 }
671 return super.visitExpressionFunctionBody(node); 671 return super.visitExpressionFunctionBody(node);
672 } finally { 672 } finally {
673 _inAsync = wasInAsync; 673 _inAsync = wasInAsync;
674 _inGenerator = wasInGenerator; 674 _inGenerator = wasInGenerator;
675 } 675 }
676 } 676 }
677 677
678 @override 678 @override
679 Object visitExtendsClause(ExtendsClause node) {
680 _checkForImplicitDynamicType(node.superclass);
681 return super.visitExtendsClause(node);
682 }
683
684 @override
679 Object visitFieldDeclaration(FieldDeclaration node) { 685 Object visitFieldDeclaration(FieldDeclaration node) {
680 _isInStaticVariableDeclaration = node.isStatic; 686 _isInStaticVariableDeclaration = node.isStatic;
681 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration; 687 _isInInstanceVariableDeclaration = !_isInStaticVariableDeclaration;
682 if (_isInInstanceVariableDeclaration) { 688 if (_isInInstanceVariableDeclaration) {
683 VariableDeclarationList variables = node.fields; 689 VariableDeclarationList variables = node.fields;
684 if (variables.isConst) { 690 if (variables.isConst) {
685 _errorReporter.reportErrorForToken( 691 _errorReporter.reportErrorForToken(
686 CompileTimeErrorCode.CONST_INSTANCE_FIELD, variables.keyword); 692 CompileTimeErrorCode.CONST_INSTANCE_FIELD, variables.keyword);
687 } 693 }
688 } 694 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
740 } 746 }
741 _checkForNonVoidReturnTypeForSetter(returnType); 747 _checkForNonVoidReturnTypeForSetter(returnType);
742 } 748 }
743 } 749 }
744 if (node.isSetter) { 750 if (node.isSetter) {
745 _checkForInvalidModifierOnBody(node.functionExpression.body, 751 _checkForInvalidModifierOnBody(node.functionExpression.body,
746 CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER); 752 CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER);
747 } 753 }
748 _checkForTypeAnnotationDeferredClass(returnType); 754 _checkForTypeAnnotationDeferredClass(returnType);
749 _checkForIllegalReturnType(returnType); 755 _checkForIllegalReturnType(returnType);
756 _checkForImplicitDynamicReturn(node, node.element);
750 return super.visitFunctionDeclaration(node); 757 return super.visitFunctionDeclaration(node);
751 } finally { 758 } finally {
752 _enclosingFunction = outerFunction; 759 _enclosingFunction = outerFunction;
753 } 760 }
754 } 761 }
755 762
756 @override 763 @override
757 Object visitFunctionExpression(FunctionExpression node) { 764 Object visitFunctionExpression(FunctionExpression node) {
758 // If this function expression is wrapped in a function declaration, don't 765 // If this function expression is wrapped in a function declaration, don't
759 // change the enclosingFunction field. 766 // change the enclosingFunction field.
(...skipping 14 matching lines...) Expand all
774 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 781 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
775 Expression functionExpression = node.function; 782 Expression functionExpression = node.function;
776 DartType expressionType = functionExpression.staticType; 783 DartType expressionType = functionExpression.staticType;
777 if (!_isFunctionType(expressionType)) { 784 if (!_isFunctionType(expressionType)) {
778 _errorReporter.reportErrorForNode( 785 _errorReporter.reportErrorForNode(
779 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 786 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION,
780 functionExpression); 787 functionExpression);
781 } else if (expressionType is FunctionType) { 788 } else if (expressionType is FunctionType) {
782 _checkTypeArguments(expressionType.element, node.typeArguments); 789 _checkTypeArguments(expressionType.element, node.typeArguments);
783 } 790 }
791 _checkForImplicitDynamicInvoke(node);
784 return super.visitFunctionExpressionInvocation(node); 792 return super.visitFunctionExpressionInvocation(node);
785 } 793 }
786 794
787 @override 795 @override
788 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 796 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
789 _checkForBuiltInIdentifierAsName( 797 _checkForBuiltInIdentifierAsName(
790 node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME); 798 node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME);
791 _checkForDefaultValueInFunctionTypeAlias(node); 799 _checkForDefaultValueInFunctionTypeAlias(node);
792 _checkForTypeAliasCannotReferenceItself_function(node); 800 _checkForTypeAliasCannotReferenceItself_function(node);
793 return super.visitFunctionTypeAlias(node); 801 return super.visitFunctionTypeAlias(node);
794 } 802 }
795 803
796 @override 804 @override
797 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 805 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
798 bool old = _isInFunctionTypedFormalParameter; 806 bool old = _isInFunctionTypedFormalParameter;
799 _isInFunctionTypedFormalParameter = true; 807 _isInFunctionTypedFormalParameter = true;
800 try { 808 try {
801 _checkForTypeAnnotationDeferredClass(node.returnType); 809 _checkForTypeAnnotationDeferredClass(node.returnType);
810
811 // TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and
812 // we can get the function element via `node?.element?.type?.element` but
813 // it doesn't have hasImplicitReturnType set correctly.
814 if (!_options.implicitDynamic && node.returnType == null) {
815 DartType parameterType = node.element.type;
816 if (parameterType is FunctionType &&
817 parameterType.returnType.isDynamic) {
818 _errorReporter.reportErrorForNode(
819 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [node.identifier]);
820 }
821 }
802 return super.visitFunctionTypedFormalParameter(node); 822 return super.visitFunctionTypedFormalParameter(node);
803 } finally { 823 } finally {
804 _isInFunctionTypedFormalParameter = old; 824 _isInFunctionTypedFormalParameter = old;
805 } 825 }
806 } 826 }
807 827
808 @override 828 @override
809 Object visitIfStatement(IfStatement node) { 829 Object visitIfStatement(IfStatement node) {
810 _checkForNonBoolCondition(node.condition); 830 _checkForNonBoolCondition(node.condition);
811 return super.visitIfStatement(node); 831 return super.visitIfStatement(node);
812 } 832 }
813 833
814 @override 834 @override
835 Object visitImplementsClause(ImplementsClause node) {
836 node.interfaces.forEach(_checkForImplicitDynamicType);
837 return super.visitImplementsClause(node);
838 }
839
840 @override
815 Object visitImportDirective(ImportDirective node) { 841 Object visitImportDirective(ImportDirective node) {
816 ImportElement importElement = node.element; 842 ImportElement importElement = node.element;
817 if (importElement != null) { 843 if (importElement != null) {
818 _checkForImportDuplicateLibraryName(node, importElement); 844 _checkForImportDuplicateLibraryName(node, importElement);
819 _checkForImportInternalLibrary(node, importElement); 845 _checkForImportInternalLibrary(node, importElement);
820 } 846 }
821 return super.visitImportDirective(node); 847 return super.visitImportDirective(node);
822 } 848 }
823 849
824 @override 850 @override
(...skipping 16 matching lines...) Expand all
841 if (_isInConstInstanceCreation) { 867 if (_isInConstInstanceCreation) {
842 _checkForConstWithNonConst(node); 868 _checkForConstWithNonConst(node);
843 _checkForConstWithUndefinedConstructor( 869 _checkForConstWithUndefinedConstructor(
844 node, constructorName, typeName); 870 node, constructorName, typeName);
845 _checkForConstWithTypeParameters(typeName); 871 _checkForConstWithTypeParameters(typeName);
846 _checkForConstDeferredClass(node, constructorName, typeName); 872 _checkForConstDeferredClass(node, constructorName, typeName);
847 } else { 873 } else {
848 _checkForNewWithUndefinedConstructor(node, constructorName, typeName); 874 _checkForNewWithUndefinedConstructor(node, constructorName, typeName);
849 } 875 }
850 } 876 }
877 _checkForImplicitDynamicType(typeName);
851 return super.visitInstanceCreationExpression(node); 878 return super.visitInstanceCreationExpression(node);
852 } finally { 879 } finally {
853 _isInConstInstanceCreation = wasInConstInstanceCreation; 880 _isInConstInstanceCreation = wasInConstInstanceCreation;
854 } 881 }
855 } 882 }
856 883
857 @override 884 @override
858 Object visitIsExpression(IsExpression node) { 885 Object visitIsExpression(IsExpression node) {
859 _checkForTypeAnnotationDeferredClass(node.type); 886 _checkForTypeAnnotationDeferredClass(node.type);
860 return super.visitIsExpression(node); 887 return super.visitIsExpression(node);
861 } 888 }
862 889
863 @override 890 @override
864 Object visitListLiteral(ListLiteral node) { 891 Object visitListLiteral(ListLiteral node) {
865 TypeArgumentList typeArguments = node.typeArguments; 892 TypeArgumentList typeArguments = node.typeArguments;
866 if (typeArguments != null) { 893 if (typeArguments != null) {
867 if (node.constKeyword != null) { 894 if (node.constKeyword != null) {
868 NodeList<TypeName> arguments = typeArguments.arguments; 895 NodeList<TypeName> arguments = typeArguments.arguments;
869 if (arguments.length != 0) { 896 if (arguments.length != 0) {
870 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, 897 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
871 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 898 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
872 } 899 }
873 } 900 }
874 _checkForExpectedOneListTypeArgument(node, typeArguments); 901 _checkForExpectedOneListTypeArgument(node, typeArguments);
875 } 902 }
876 903 _checkForImplicitDynamicTypedLiteral(node);
877 _checkForListElementTypeNotAssignable(node); 904 _checkForListElementTypeNotAssignable(node);
878 return super.visitListLiteral(node); 905 return super.visitListLiteral(node);
879 } 906 }
880 907
881 @override 908 @override
882 Object visitMapLiteral(MapLiteral node) { 909 Object visitMapLiteral(MapLiteral node) {
883 TypeArgumentList typeArguments = node.typeArguments; 910 TypeArgumentList typeArguments = node.typeArguments;
884 if (typeArguments != null) { 911 if (typeArguments != null) {
885 NodeList<TypeName> arguments = typeArguments.arguments; 912 NodeList<TypeName> arguments = typeArguments.arguments;
886 if (arguments.length != 0) { 913 if (arguments.length != 0) {
887 if (node.constKeyword != null) { 914 if (node.constKeyword != null) {
888 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, 915 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
889 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 916 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
890 } 917 }
891 } 918 }
892 _checkExpectedTwoMapTypeArguments(typeArguments); 919 _checkExpectedTwoMapTypeArguments(typeArguments);
893 } 920 }
894 921 _checkForImplicitDynamicTypedLiteral(node);
895 _checkForMapTypeNotAssignable(node); 922 _checkForMapTypeNotAssignable(node);
896 _checkForNonConstMapAsExpressionStatement(node); 923 _checkForNonConstMapAsExpressionStatement(node);
897 return super.visitMapLiteral(node); 924 return super.visitMapLiteral(node);
898 } 925 }
899 926
900 @override 927 @override
901 Object visitMethodDeclaration(MethodDeclaration node) { 928 Object visitMethodDeclaration(MethodDeclaration node) {
902 ExecutableElement previousFunction = _enclosingFunction; 929 ExecutableElement previousFunction = _enclosingFunction;
903 try { 930 try {
904 _isInStaticMethod = node.isStatic; 931 _isInStaticMethod = node.isStatic;
(...skipping 18 matching lines...) Expand all
923 _checkForConflictingStaticSetterAndInstanceMember(node); 950 _checkForConflictingStaticSetterAndInstanceMember(node);
924 } else if (node.isOperator) { 951 } else if (node.isOperator) {
925 _checkForOptionalParameterInOperator(node); 952 _checkForOptionalParameterInOperator(node);
926 _checkForWrongNumberOfParametersForOperator(node); 953 _checkForWrongNumberOfParametersForOperator(node);
927 _checkForNonVoidReturnTypeForOperator(node); 954 _checkForNonVoidReturnTypeForOperator(node);
928 } 955 }
929 _checkForConcreteClassWithAbstractMember(node); 956 _checkForConcreteClassWithAbstractMember(node);
930 _checkForAllInvalidOverrideErrorCodesForMethod(node); 957 _checkForAllInvalidOverrideErrorCodesForMethod(node);
931 _checkForTypeAnnotationDeferredClass(returnTypeName); 958 _checkForTypeAnnotationDeferredClass(returnTypeName);
932 _checkForIllegalReturnType(returnTypeName); 959 _checkForIllegalReturnType(returnTypeName);
960 _checkForImplicitDynamicReturn(node, node.element);
933 _checkForMustCallSuper(node); 961 _checkForMustCallSuper(node);
934 return super.visitMethodDeclaration(node); 962 return super.visitMethodDeclaration(node);
935 } finally { 963 } finally {
936 _enclosingFunction = previousFunction; 964 _enclosingFunction = previousFunction;
937 _isInStaticMethod = false; 965 _isInStaticMethod = false;
938 } 966 }
939 } 967 }
940 968
941 @override 969 @override
942 Object visitMethodInvocation(MethodInvocation node) { 970 Object visitMethodInvocation(MethodInvocation node) {
943 Expression target = node.realTarget; 971 Expression target = node.realTarget;
944 SimpleIdentifier methodName = node.methodName; 972 SimpleIdentifier methodName = node.methodName;
945 if (target != null) { 973 if (target != null) {
946 ClassElement typeReference = ElementResolver.getTypeReference(target); 974 ClassElement typeReference = ElementResolver.getTypeReference(target);
947 _checkForStaticAccessToInstanceMember(typeReference, methodName); 975 _checkForStaticAccessToInstanceMember(typeReference, methodName);
948 _checkForInstanceAccessToStaticMember(typeReference, methodName); 976 _checkForInstanceAccessToStaticMember(typeReference, methodName);
949 } else { 977 } else {
950 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); 978 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName);
951 } 979 }
952 _checkTypeArguments( 980 _checkTypeArguments(
953 node.methodName.staticElement, node.typeArguments, target?.staticType); 981 node.methodName.staticElement, node.typeArguments, target?.staticType);
982 _checkForImplicitDynamicInvoke(node);
954 return super.visitMethodInvocation(node); 983 return super.visitMethodInvocation(node);
955 } 984 }
956 985
957 @override 986 @override
958 Object visitNativeClause(NativeClause node) { 987 Object visitNativeClause(NativeClause node) {
959 // TODO(brianwilkerson) Figure out the right rule for when 'native' is 988 // TODO(brianwilkerson) Figure out the right rule for when 'native' is
960 // allowed. 989 // allowed.
961 if (!_isInSystemLibrary) { 990 if (!_isInSystemLibrary) {
962 _errorReporter.reportErrorForNode( 991 _errorReporter.reportErrorForNode(
963 ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node); 992 ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 } 1068 }
1040 _checkForAllReturnStatementErrorCodes(node); 1069 _checkForAllReturnStatementErrorCodes(node);
1041 return super.visitReturnStatement(node); 1070 return super.visitReturnStatement(node);
1042 } 1071 }
1043 1072
1044 @override 1073 @override
1045 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 1074 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
1046 _checkForConstFormalParameter(node); 1075 _checkForConstFormalParameter(node);
1047 _checkForPrivateOptionalParameter(node); 1076 _checkForPrivateOptionalParameter(node);
1048 _checkForTypeAnnotationDeferredClass(node.type); 1077 _checkForTypeAnnotationDeferredClass(node.type);
1078
1079 // Checks for an implicit dynamic parameter type.
1080 //
1081 // We can skip other parameter kinds besides simple formal, because:
1082 // - DefaultFormalParameter contains a simple one, so it gets here,
1083 // - FieldFormalParameter error should be reported on the field,
1084 // - FunctionTypedFormalParameter is a function type, not dynamic.
1085 _checkForImplicitDynamicIdentifier(node, node.identifier);
1086
1049 return super.visitSimpleFormalParameter(node); 1087 return super.visitSimpleFormalParameter(node);
1050 } 1088 }
1051 1089
1052 @override 1090 @override
1053 Object visitSimpleIdentifier(SimpleIdentifier node) { 1091 Object visitSimpleIdentifier(SimpleIdentifier node) {
1054 _checkForImplicitThisReferenceInInitializer(node); 1092 _checkForImplicitThisReferenceInInitializer(node);
1055 if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) { 1093 if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) {
1056 _checkForUnqualifiedReferenceToNonLocalStaticMember(node); 1094 _checkForUnqualifiedReferenceToNonLocalStaticMember(node);
1057 } 1095 }
1058 return super.visitSimpleIdentifier(node); 1096 return super.visitSimpleIdentifier(node);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 _checkForTypeParameterReferencedByStatic(node); 1147 _checkForTypeParameterReferencedByStatic(node);
1110 return super.visitTypeName(node); 1148 return super.visitTypeName(node);
1111 } 1149 }
1112 1150
1113 @override 1151 @override
1114 Object visitTypeParameter(TypeParameter node) { 1152 Object visitTypeParameter(TypeParameter node) {
1115 _checkForBuiltInIdentifierAsName(node.name, 1153 _checkForBuiltInIdentifierAsName(node.name,
1116 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME); 1154 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME);
1117 _checkForTypeParameterSupertypeOfItsBound(node); 1155 _checkForTypeParameterSupertypeOfItsBound(node);
1118 _checkForTypeAnnotationDeferredClass(node.bound); 1156 _checkForTypeAnnotationDeferredClass(node.bound);
1157 _checkForImplicitDynamicType(node.bound);
1119 return super.visitTypeParameter(node); 1158 return super.visitTypeParameter(node);
1120 } 1159 }
1121 1160
1122 @override 1161 @override
1123 Object visitVariableDeclaration(VariableDeclaration node) { 1162 Object visitVariableDeclaration(VariableDeclaration node) {
1124 SimpleIdentifier nameNode = node.name; 1163 SimpleIdentifier nameNode = node.name;
1125 Expression initializerNode = node.initializer; 1164 Expression initializerNode = node.initializer;
1126 // do checks 1165 // do checks
1127 _checkForInvalidAssignment(nameNode, initializerNode); 1166 _checkForInvalidAssignment(nameNode, initializerNode);
1167 _checkForImplicitDynamicIdentifier(node, nameNode);
1128 // visit name 1168 // visit name
1129 nameNode.accept(this); 1169 nameNode.accept(this);
1130 // visit initializer 1170 // visit initializer
1131 String name = nameNode.name; 1171 String name = nameNode.name;
1132 _namesForReferenceToDeclaredVariableInInitializer.add(name); 1172 _namesForReferenceToDeclaredVariableInInitializer.add(name);
1133 bool wasInInstanceVariableInitializer = _isInInstanceVariableInitializer; 1173 bool wasInInstanceVariableInitializer = _isInInstanceVariableInitializer;
1134 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; 1174 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration;
1135 try { 1175 try {
1136 if (initializerNode != null) { 1176 if (initializerNode != null) {
1137 initializerNode.accept(this); 1177 initializerNode.accept(this);
(...skipping 18 matching lines...) Expand all
1156 return super.visitVariableDeclarationStatement(node); 1196 return super.visitVariableDeclarationStatement(node);
1157 } 1197 }
1158 1198
1159 @override 1199 @override
1160 Object visitWhileStatement(WhileStatement node) { 1200 Object visitWhileStatement(WhileStatement node) {
1161 _checkForNonBoolCondition(node.condition); 1201 _checkForNonBoolCondition(node.condition);
1162 return super.visitWhileStatement(node); 1202 return super.visitWhileStatement(node);
1163 } 1203 }
1164 1204
1165 @override 1205 @override
1206 Object visitWithClause(WithClause node) {
1207 node.mixinTypes.forEach(_checkForImplicitDynamicType);
1208 return super.visitWithClause(node);
1209 }
1210
1211 @override
1166 Object visitYieldStatement(YieldStatement node) { 1212 Object visitYieldStatement(YieldStatement node) {
1167 if (_inGenerator) { 1213 if (_inGenerator) {
1168 _checkForYieldOfInvalidType(node.expression, node.star != null); 1214 _checkForYieldOfInvalidType(node.expression, node.star != null);
1169 } else { 1215 } else {
1170 CompileTimeErrorCode errorCode; 1216 CompileTimeErrorCode errorCode;
1171 if (node.star != null) { 1217 if (node.star != null) {
1172 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; 1218 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR;
1173 } else { 1219 } else {
1174 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; 1220 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR;
1175 } 1221 }
(...skipping 2355 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 bool foundError = false; 3577 bool foundError = false;
3532 for (TypeName type in clause.interfaces) { 3578 for (TypeName type in clause.interfaces) {
3533 if (_checkForExtendsOrImplementsDisallowedClass( 3579 if (_checkForExtendsOrImplementsDisallowedClass(
3534 type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)) { 3580 type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)) {
3535 foundError = true; 3581 foundError = true;
3536 } 3582 }
3537 } 3583 }
3538 return foundError; 3584 return foundError;
3539 } 3585 }
3540 3586
3587 void _checkForImplicitDynamicIdentifier(AstNode node, Identifier id) {
3588 if (_options.implicitDynamic) {
3589 return;
3590 }
3591 VariableElement variable = getVariableElement(id);
3592 if (variable != null &&
3593 variable.hasImplicitType &&
3594 variable.type.isDynamic) {
3595 ErrorCode errorCode;
3596 if (variable is FieldElement) {
3597 errorCode = StrongModeCode.IMPLICIT_DYNAMIC_FIELD;
3598 } else if (variable is ParameterElement) {
3599 errorCode = StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER;
3600 } else {
3601 errorCode = StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE;
3602 }
3603 _errorReporter.reportErrorForNode(errorCode, node, [id]);
3604 }
3605 }
3606
3607 void _checkForImplicitDynamicInvoke(InvocationExpression node) {
3608 if (_options.implicitDynamic ||
3609 node == null ||
3610 node.typeArguments != null) {
3611 return;
3612 }
3613 DartType invokeType = node.staticInvokeType;
3614 DartType declaredType = node.function.staticType;
3615 if (invokeType is FunctionType && declaredType is FunctionType) {
3616 Iterable<DartType> typeArgs =
3617 FunctionTypeImpl.recoverTypeArguments(declaredType, invokeType);
3618 if (typeArgs.any((t) => t.isDynamic)) {
3619 // Issue an error depending on what we're trying to call.
3620 Expression function = node.function;
3621 if (function is Identifier) {
3622 Element element = function.staticElement;
3623 if (element is MethodElement) {
3624 _errorReporter.reportErrorForNode(
3625 StrongModeCode.IMPLICIT_DYNAMIC_METHOD,
3626 node.function,
3627 [element.displayName, element.typeParameters.join(', ')]);
3628 return;
3629 }
3630
3631 if (element is FunctionElement) {
3632 _errorReporter.reportErrorForNode(
3633 StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION,
3634 node.function,
3635 [element.displayName, element.typeParameters.join(', ')]);
3636 return;
3637 }
3638 }
3639
3640 // The catch all case if neither of those matched.
3641 // For example, invoking a function expression.
3642 _errorReporter.reportErrorForNode(
3643 StrongModeCode.IMPLICIT_DYNAMIC_INVOKE,
3644 node.function,
3645 [declaredType]);
3646 }
3647 }
3648 }
3649
3650 void _checkForImplicitDynamicReturn(AstNode node, ExecutableElement element) {
3651 if (_options.implicitDynamic) {
3652 return;
3653 }
3654 if (element is PropertyAccessorElement && element.isSetter) {
3655 return;
3656 }
3657 if (element != null &&
3658 element.hasImplicitReturnType &&
3659 element.returnType.isDynamic) {
3660 _errorReporter.reportErrorForNode(
3661 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [element.displayName]);
3662 }
3663 }
3664
3665 void _checkForImplicitDynamicType(TypeName node) {
3666 if (_options.implicitDynamic ||
3667 node == null ||
3668 node.typeArguments != null) {
3669 return;
3670 }
3671 DartType type = node.type;
3672 if (type is ParameterizedType &&
3673 type.typeArguments.isNotEmpty &&
3674 type.typeArguments.any((t) => t.isDynamic)) {
3675 _errorReporter.reportErrorForNode(
3676 StrongModeCode.IMPLICIT_DYNAMIC_TYPE, node, [type]);
3677 }
3678 }
3679
3680 void _checkForImplicitDynamicTypedLiteral(TypedLiteral node) {
3681 if (_options.implicitDynamic || node.typeArguments != null) {
3682 return;
3683 }
3684 DartType type = node.staticType;
3685 // It's an error if either the key or value was inferred as dynamic.
3686 if (type is InterfaceType && type.typeArguments.any((t) => t.isDynamic)) {
3687 ErrorCode errorCode = node is ListLiteral
3688 ? StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL
3689 : StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL;
3690 _errorReporter.reportErrorForNode(errorCode, node);
3691 }
3692 }
3693
3541 /** 3694 /**
3542 * Verify that if the given [identifier] is part of a constructor initializer, 3695 * Verify that if the given [identifier] is part of a constructor initializer,
3543 * then it does not implicitly reference 'this' expression. 3696 * then it does not implicitly reference 'this' expression.
3544 * 3697 *
3545 * See [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER], and 3698 * See [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER], and
3546 * [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]. 3699 * [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC].
3547 * TODO(scheglov) rename thid method 3700 * TODO(scheglov) rename thid method
3548 */ 3701 */
3549 void _checkForImplicitThisReferenceInInitializer( 3702 void _checkForImplicitThisReferenceInInitializer(
3550 SimpleIdentifier identifier) { 3703 SimpleIdentifier identifier) {
(...skipping 2756 matching lines...) Expand 10 before | Expand all | Expand 10 after
6307 class _InvocationCollector extends RecursiveAstVisitor { 6460 class _InvocationCollector extends RecursiveAstVisitor {
6308 final List<String> superCalls = <String>[]; 6461 final List<String> superCalls = <String>[];
6309 6462
6310 @override 6463 @override
6311 visitMethodInvocation(MethodInvocation node) { 6464 visitMethodInvocation(MethodInvocation node) {
6312 if (node.target is SuperExpression) { 6465 if (node.target is SuperExpression) {
6313 superCalls.add(node.methodName.name); 6466 superCalls.add(node.methodName.name);
6314 } 6467 }
6315 } 6468 }
6316 } 6469 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/error.dart ('k') | pkg/analyzer/test/src/task/strong/checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698