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

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: Created 4 years, 6 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);
Leaf 2016/06/24 21:40:25 Will this fire on things that are setters only? I
Jennifer Messerly 2016/06/27 18:38:17 There's a check inside `_checkForImplicitDynamicRe
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.
760 if (node.parent is! FunctionDeclaration) { 767 if (node.parent is! FunctionDeclaration) {
761 ExecutableElement outerFunction = _enclosingFunction; 768 ExecutableElement outerFunction = _enclosingFunction;
762 try { 769 try {
763 _enclosingFunction = node.element; 770 _enclosingFunction = node.element;
771 // TODO(jmesserly): there's no way to actually write this `dynamic`
772 // explicitly. Maybe this shouldn't be an error?
773 _checkForImplicitDynamicReturn(node, node.element);
Leaf 2016/06/24 21:40:25 Good question. :) I think probably? But this mi
Jennifer Messerly 2016/06/27 18:38:17 Sounds good. Based on our chat I'm going to leave
764 return super.visitFunctionExpression(node); 774 return super.visitFunctionExpression(node);
765 } finally { 775 } finally {
766 _enclosingFunction = outerFunction; 776 _enclosingFunction = outerFunction;
767 } 777 }
768 } else { 778 } else {
769 return super.visitFunctionExpression(node); 779 return super.visitFunctionExpression(node);
770 } 780 }
771 } 781 }
772 782
773 @override 783 @override
774 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) { 784 Object visitFunctionExpressionInvocation(FunctionExpressionInvocation node) {
775 Expression functionExpression = node.function; 785 Expression functionExpression = node.function;
776 DartType expressionType = functionExpression.staticType; 786 DartType expressionType = functionExpression.staticType;
777 if (!_isFunctionType(expressionType)) { 787 if (!_isFunctionType(expressionType)) {
778 _errorReporter.reportErrorForNode( 788 _errorReporter.reportErrorForNode(
779 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION, 789 StaticTypeWarningCode.INVOCATION_OF_NON_FUNCTION_EXPRESSION,
780 functionExpression); 790 functionExpression);
781 } else if (expressionType is FunctionType) { 791 } else if (expressionType is FunctionType) {
782 _checkTypeArguments(expressionType.element, node.typeArguments); 792 _checkTypeArguments(expressionType.element, node.typeArguments);
783 } 793 }
794 _checkForImplicitDynamicInvoke(node);
784 return super.visitFunctionExpressionInvocation(node); 795 return super.visitFunctionExpressionInvocation(node);
785 } 796 }
786 797
787 @override 798 @override
788 Object visitFunctionTypeAlias(FunctionTypeAlias node) { 799 Object visitFunctionTypeAlias(FunctionTypeAlias node) {
789 _checkForBuiltInIdentifierAsName( 800 _checkForBuiltInIdentifierAsName(
790 node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME); 801 node.name, CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPEDEF_NAME);
791 _checkForDefaultValueInFunctionTypeAlias(node); 802 _checkForDefaultValueInFunctionTypeAlias(node);
792 _checkForTypeAliasCannotReferenceItself_function(node); 803 _checkForTypeAliasCannotReferenceItself_function(node);
793 return super.visitFunctionTypeAlias(node); 804 return super.visitFunctionTypeAlias(node);
794 } 805 }
795 806
796 @override 807 @override
797 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) { 808 Object visitFunctionTypedFormalParameter(FunctionTypedFormalParameter node) {
798 bool old = _isInFunctionTypedFormalParameter; 809 bool old = _isInFunctionTypedFormalParameter;
799 _isInFunctionTypedFormalParameter = true; 810 _isInFunctionTypedFormalParameter = true;
800 try { 811 try {
801 _checkForTypeAnnotationDeferredClass(node.returnType); 812 _checkForTypeAnnotationDeferredClass(node.returnType);
813
814 // TODO(jmesserly): ideally we'd use _checkForImplicitDynamicReturn, and
815 // we can get the function element via `node?.element?.type?.element` but
816 // it doesn't have hasImplicitReturnType set correctly.
817 if (!_options.implicitDynamic && node.returnType == null) {
818 DartType parameterType = node.element.type;
819 if (parameterType is FunctionType &&
820 parameterType.returnType.isDynamic) {
821 _errorReporter.reportErrorForNode(
822 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [node.identifier]);
823 }
824 }
802 return super.visitFunctionTypedFormalParameter(node); 825 return super.visitFunctionTypedFormalParameter(node);
803 } finally { 826 } finally {
804 _isInFunctionTypedFormalParameter = old; 827 _isInFunctionTypedFormalParameter = old;
805 } 828 }
806 } 829 }
807 830
808 @override 831 @override
809 Object visitIfStatement(IfStatement node) { 832 Object visitIfStatement(IfStatement node) {
810 _checkForNonBoolCondition(node.condition); 833 _checkForNonBoolCondition(node.condition);
811 return super.visitIfStatement(node); 834 return super.visitIfStatement(node);
812 } 835 }
813 836
814 @override 837 @override
838 Object visitImplementsClause(ImplementsClause node) {
839 node.interfaces.forEach(_checkForImplicitDynamicType);
840 return super.visitImplementsClause(node);
841 }
842
843 @override
815 Object visitImportDirective(ImportDirective node) { 844 Object visitImportDirective(ImportDirective node) {
816 ImportElement importElement = node.element; 845 ImportElement importElement = node.element;
817 if (importElement != null) { 846 if (importElement != null) {
818 _checkForImportDuplicateLibraryName(node, importElement); 847 _checkForImportDuplicateLibraryName(node, importElement);
819 _checkForImportInternalLibrary(node, importElement); 848 _checkForImportInternalLibrary(node, importElement);
820 } 849 }
821 return super.visitImportDirective(node); 850 return super.visitImportDirective(node);
822 } 851 }
823 852
824 @override 853 @override
(...skipping 16 matching lines...) Expand all
841 if (_isInConstInstanceCreation) { 870 if (_isInConstInstanceCreation) {
842 _checkForConstWithNonConst(node); 871 _checkForConstWithNonConst(node);
843 _checkForConstWithUndefinedConstructor( 872 _checkForConstWithUndefinedConstructor(
844 node, constructorName, typeName); 873 node, constructorName, typeName);
845 _checkForConstWithTypeParameters(typeName); 874 _checkForConstWithTypeParameters(typeName);
846 _checkForConstDeferredClass(node, constructorName, typeName); 875 _checkForConstDeferredClass(node, constructorName, typeName);
847 } else { 876 } else {
848 _checkForNewWithUndefinedConstructor(node, constructorName, typeName); 877 _checkForNewWithUndefinedConstructor(node, constructorName, typeName);
849 } 878 }
850 } 879 }
880 _checkForImplicitDynamicType(typeName);
851 return super.visitInstanceCreationExpression(node); 881 return super.visitInstanceCreationExpression(node);
852 } finally { 882 } finally {
853 _isInConstInstanceCreation = wasInConstInstanceCreation; 883 _isInConstInstanceCreation = wasInConstInstanceCreation;
854 } 884 }
855 } 885 }
856 886
857 @override 887 @override
858 Object visitIsExpression(IsExpression node) { 888 Object visitIsExpression(IsExpression node) {
859 _checkForTypeAnnotationDeferredClass(node.type); 889 _checkForTypeAnnotationDeferredClass(node.type);
860 return super.visitIsExpression(node); 890 return super.visitIsExpression(node);
861 } 891 }
862 892
863 @override 893 @override
864 Object visitListLiteral(ListLiteral node) { 894 Object visitListLiteral(ListLiteral node) {
865 TypeArgumentList typeArguments = node.typeArguments; 895 TypeArgumentList typeArguments = node.typeArguments;
866 if (typeArguments != null) { 896 if (typeArguments != null) {
867 if (node.constKeyword != null) { 897 if (node.constKeyword != null) {
868 NodeList<TypeName> arguments = typeArguments.arguments; 898 NodeList<TypeName> arguments = typeArguments.arguments;
869 if (arguments.length != 0) { 899 if (arguments.length != 0) {
870 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, 900 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
871 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 901 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
872 } 902 }
873 } 903 }
874 _checkForExpectedOneListTypeArgument(node, typeArguments); 904 _checkForExpectedOneListTypeArgument(node, typeArguments);
875 } 905 }
876 906 _checkForImplicitDynamicTypedLiteral(node);
877 _checkForListElementTypeNotAssignable(node); 907 _checkForListElementTypeNotAssignable(node);
878 return super.visitListLiteral(node); 908 return super.visitListLiteral(node);
879 } 909 }
880 910
881 @override 911 @override
882 Object visitMapLiteral(MapLiteral node) { 912 Object visitMapLiteral(MapLiteral node) {
883 TypeArgumentList typeArguments = node.typeArguments; 913 TypeArgumentList typeArguments = node.typeArguments;
884 if (typeArguments != null) { 914 if (typeArguments != null) {
885 NodeList<TypeName> arguments = typeArguments.arguments; 915 NodeList<TypeName> arguments = typeArguments.arguments;
886 if (arguments.length != 0) { 916 if (arguments.length != 0) {
887 if (node.constKeyword != null) { 917 if (node.constKeyword != null) {
888 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, 918 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
889 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 919 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
890 } 920 }
891 } 921 }
892 _checkExpectedTwoMapTypeArguments(typeArguments); 922 _checkExpectedTwoMapTypeArguments(typeArguments);
893 } 923 }
894 924 _checkForImplicitDynamicTypedLiteral(node);
895 _checkForMapTypeNotAssignable(node); 925 _checkForMapTypeNotAssignable(node);
896 _checkForNonConstMapAsExpressionStatement(node); 926 _checkForNonConstMapAsExpressionStatement(node);
897 return super.visitMapLiteral(node); 927 return super.visitMapLiteral(node);
898 } 928 }
899 929
900 @override 930 @override
901 Object visitMethodDeclaration(MethodDeclaration node) { 931 Object visitMethodDeclaration(MethodDeclaration node) {
902 ExecutableElement previousFunction = _enclosingFunction; 932 ExecutableElement previousFunction = _enclosingFunction;
903 try { 933 try {
904 _isInStaticMethod = node.isStatic; 934 _isInStaticMethod = node.isStatic;
(...skipping 18 matching lines...) Expand all
923 _checkForConflictingStaticSetterAndInstanceMember(node); 953 _checkForConflictingStaticSetterAndInstanceMember(node);
924 } else if (node.isOperator) { 954 } else if (node.isOperator) {
925 _checkForOptionalParameterInOperator(node); 955 _checkForOptionalParameterInOperator(node);
926 _checkForWrongNumberOfParametersForOperator(node); 956 _checkForWrongNumberOfParametersForOperator(node);
927 _checkForNonVoidReturnTypeForOperator(node); 957 _checkForNonVoidReturnTypeForOperator(node);
928 } 958 }
929 _checkForConcreteClassWithAbstractMember(node); 959 _checkForConcreteClassWithAbstractMember(node);
930 _checkForAllInvalidOverrideErrorCodesForMethod(node); 960 _checkForAllInvalidOverrideErrorCodesForMethod(node);
931 _checkForTypeAnnotationDeferredClass(returnTypeName); 961 _checkForTypeAnnotationDeferredClass(returnTypeName);
932 _checkForIllegalReturnType(returnTypeName); 962 _checkForIllegalReturnType(returnTypeName);
963 _checkForImplicitDynamicReturn(node, node.element);
933 _checkForMustCallSuper(node); 964 _checkForMustCallSuper(node);
934 return super.visitMethodDeclaration(node); 965 return super.visitMethodDeclaration(node);
935 } finally { 966 } finally {
936 _enclosingFunction = previousFunction; 967 _enclosingFunction = previousFunction;
937 _isInStaticMethod = false; 968 _isInStaticMethod = false;
938 } 969 }
939 } 970 }
940 971
941 @override 972 @override
942 Object visitMethodInvocation(MethodInvocation node) { 973 Object visitMethodInvocation(MethodInvocation node) {
943 Expression target = node.realTarget; 974 Expression target = node.realTarget;
944 SimpleIdentifier methodName = node.methodName; 975 SimpleIdentifier methodName = node.methodName;
945 if (target != null) { 976 if (target != null) {
946 ClassElement typeReference = ElementResolver.getTypeReference(target); 977 ClassElement typeReference = ElementResolver.getTypeReference(target);
947 _checkForStaticAccessToInstanceMember(typeReference, methodName); 978 _checkForStaticAccessToInstanceMember(typeReference, methodName);
948 _checkForInstanceAccessToStaticMember(typeReference, methodName); 979 _checkForInstanceAccessToStaticMember(typeReference, methodName);
949 } else { 980 } else {
950 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName); 981 _checkForUnqualifiedReferenceToNonLocalStaticMember(methodName);
951 } 982 }
952 _checkTypeArguments( 983 _checkTypeArguments(
953 node.methodName.staticElement, node.typeArguments, target?.staticType); 984 node.methodName.staticElement, node.typeArguments, target?.staticType);
985 _checkForImplicitDynamicInvoke(node);
954 return super.visitMethodInvocation(node); 986 return super.visitMethodInvocation(node);
955 } 987 }
956 988
957 @override 989 @override
958 Object visitNativeClause(NativeClause node) { 990 Object visitNativeClause(NativeClause node) {
959 // TODO(brianwilkerson) Figure out the right rule for when 'native' is 991 // TODO(brianwilkerson) Figure out the right rule for when 'native' is
960 // allowed. 992 // allowed.
961 if (!_isInSystemLibrary) { 993 if (!_isInSystemLibrary) {
962 _errorReporter.reportErrorForNode( 994 _errorReporter.reportErrorForNode(
963 ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node); 995 ParserErrorCode.NATIVE_CLAUSE_IN_NON_SDK_CODE, node);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 } 1071 }
1040 _checkForAllReturnStatementErrorCodes(node); 1072 _checkForAllReturnStatementErrorCodes(node);
1041 return super.visitReturnStatement(node); 1073 return super.visitReturnStatement(node);
1042 } 1074 }
1043 1075
1044 @override 1076 @override
1045 Object visitSimpleFormalParameter(SimpleFormalParameter node) { 1077 Object visitSimpleFormalParameter(SimpleFormalParameter node) {
1046 _checkForConstFormalParameter(node); 1078 _checkForConstFormalParameter(node);
1047 _checkForPrivateOptionalParameter(node); 1079 _checkForPrivateOptionalParameter(node);
1048 _checkForTypeAnnotationDeferredClass(node.type); 1080 _checkForTypeAnnotationDeferredClass(node.type);
1081
1082 // Checks for an implicit dynamic parameter type.
1083 //
1084 // We can skip other parameter kinds besides simple formal, because:
1085 // - DefaultFormalParameter contains a simple one, so it gets here,
1086 // - FieldFormalParameter error should be reported on the field,
1087 // - FunctionTypedFormalParameter is a function type, not dynamic.
1088 _checkForImplicitDynamicIdentifier(node, node.identifier);
1089
1049 return super.visitSimpleFormalParameter(node); 1090 return super.visitSimpleFormalParameter(node);
1050 } 1091 }
1051 1092
1052 @override 1093 @override
1053 Object visitSimpleIdentifier(SimpleIdentifier node) { 1094 Object visitSimpleIdentifier(SimpleIdentifier node) {
1054 _checkForImplicitThisReferenceInInitializer(node); 1095 _checkForImplicitThisReferenceInInitializer(node);
1055 if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) { 1096 if (!_isUnqualifiedReferenceToNonLocalStaticMemberAllowed(node)) {
1056 _checkForUnqualifiedReferenceToNonLocalStaticMember(node); 1097 _checkForUnqualifiedReferenceToNonLocalStaticMember(node);
1057 } 1098 }
1058 return super.visitSimpleIdentifier(node); 1099 return super.visitSimpleIdentifier(node);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1109 _checkForTypeParameterReferencedByStatic(node); 1150 _checkForTypeParameterReferencedByStatic(node);
1110 return super.visitTypeName(node); 1151 return super.visitTypeName(node);
1111 } 1152 }
1112 1153
1113 @override 1154 @override
1114 Object visitTypeParameter(TypeParameter node) { 1155 Object visitTypeParameter(TypeParameter node) {
1115 _checkForBuiltInIdentifierAsName(node.name, 1156 _checkForBuiltInIdentifierAsName(node.name,
1116 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME); 1157 CompileTimeErrorCode.BUILT_IN_IDENTIFIER_AS_TYPE_PARAMETER_NAME);
1117 _checkForTypeParameterSupertypeOfItsBound(node); 1158 _checkForTypeParameterSupertypeOfItsBound(node);
1118 _checkForTypeAnnotationDeferredClass(node.bound); 1159 _checkForTypeAnnotationDeferredClass(node.bound);
1160 _checkForImplicitDynamicType(node.bound);
1119 return super.visitTypeParameter(node); 1161 return super.visitTypeParameter(node);
1120 } 1162 }
1121 1163
1122 @override 1164 @override
1123 Object visitVariableDeclaration(VariableDeclaration node) { 1165 Object visitVariableDeclaration(VariableDeclaration node) {
1124 SimpleIdentifier nameNode = node.name; 1166 SimpleIdentifier nameNode = node.name;
1125 Expression initializerNode = node.initializer; 1167 Expression initializerNode = node.initializer;
1126 // do checks 1168 // do checks
1127 _checkForInvalidAssignment(nameNode, initializerNode); 1169 _checkForInvalidAssignment(nameNode, initializerNode);
1170 _checkForImplicitDynamicIdentifier(node, nameNode);
1128 // visit name 1171 // visit name
1129 nameNode.accept(this); 1172 nameNode.accept(this);
1130 // visit initializer 1173 // visit initializer
1131 String name = nameNode.name; 1174 String name = nameNode.name;
1132 _namesForReferenceToDeclaredVariableInInitializer.add(name); 1175 _namesForReferenceToDeclaredVariableInInitializer.add(name);
1133 bool wasInInstanceVariableInitializer = _isInInstanceVariableInitializer; 1176 bool wasInInstanceVariableInitializer = _isInInstanceVariableInitializer;
1134 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration; 1177 _isInInstanceVariableInitializer = _isInInstanceVariableDeclaration;
1135 try { 1178 try {
1136 if (initializerNode != null) { 1179 if (initializerNode != null) {
1137 initializerNode.accept(this); 1180 initializerNode.accept(this);
(...skipping 18 matching lines...) Expand all
1156 return super.visitVariableDeclarationStatement(node); 1199 return super.visitVariableDeclarationStatement(node);
1157 } 1200 }
1158 1201
1159 @override 1202 @override
1160 Object visitWhileStatement(WhileStatement node) { 1203 Object visitWhileStatement(WhileStatement node) {
1161 _checkForNonBoolCondition(node.condition); 1204 _checkForNonBoolCondition(node.condition);
1162 return super.visitWhileStatement(node); 1205 return super.visitWhileStatement(node);
1163 } 1206 }
1164 1207
1165 @override 1208 @override
1209 Object visitWithClause(WithClause node) {
1210 node.mixinTypes.forEach(_checkForImplicitDynamicType);
1211 return super.visitWithClause(node);
1212 }
1213
1214 @override
1166 Object visitYieldStatement(YieldStatement node) { 1215 Object visitYieldStatement(YieldStatement node) {
1167 if (_inGenerator) { 1216 if (_inGenerator) {
1168 _checkForYieldOfInvalidType(node.expression, node.star != null); 1217 _checkForYieldOfInvalidType(node.expression, node.star != null);
1169 } else { 1218 } else {
1170 CompileTimeErrorCode errorCode; 1219 CompileTimeErrorCode errorCode;
1171 if (node.star != null) { 1220 if (node.star != null) {
1172 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR; 1221 errorCode = CompileTimeErrorCode.YIELD_EACH_IN_NON_GENERATOR;
1173 } else { 1222 } else {
1174 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR; 1223 errorCode = CompileTimeErrorCode.YIELD_IN_NON_GENERATOR;
1175 } 1224 }
(...skipping 2355 matching lines...) Expand 10 before | Expand all | Expand 10 after
3531 bool foundError = false; 3580 bool foundError = false;
3532 for (TypeName type in clause.interfaces) { 3581 for (TypeName type in clause.interfaces) {
3533 if (_checkForExtendsOrImplementsDisallowedClass( 3582 if (_checkForExtendsOrImplementsDisallowedClass(
3534 type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)) { 3583 type, CompileTimeErrorCode.IMPLEMENTS_DISALLOWED_CLASS)) {
3535 foundError = true; 3584 foundError = true;
3536 } 3585 }
3537 } 3586 }
3538 return foundError; 3587 return foundError;
3539 } 3588 }
3540 3589
3590 void _checkForImplicitDynamicIdentifier(AstNode node, Identifier id) {
3591 if (_options.implicitDynamic) {
3592 return;
3593 }
3594 VariableElement variable = getVariableElement(id);
3595 if (variable != null &&
3596 variable.hasImplicitType &&
3597 variable.type.isDynamic) {
Leaf 2016/06/24 21:40:26 Can we trust that type is non-null here?
Jennifer Messerly 2016/06/27 18:38:17 As near as I can tell, yes. An Element should alwa
3598 ErrorCode errorCode;
3599 if (variable is FieldElement) {
3600 errorCode = StrongModeCode.IMPLICIT_DYNAMIC_FIELD;
3601 } else if (variable is ParameterElement) {
3602 errorCode = StrongModeCode.IMPLICIT_DYNAMIC_PARAMETER;
3603 } else {
3604 errorCode = StrongModeCode.IMPLICIT_DYNAMIC_VARIABLE;
3605 }
3606 _errorReporter.reportErrorForNode(errorCode, node, [id]);
3607 }
3608 }
3609
3610 void _checkForImplicitDynamicInvoke(InvocationExpression node) {
3611 if (_options.implicitDynamic ||
3612 node == null ||
3613 node.typeArguments != null) {
3614 return;
3615 }
3616 DartType invokeType = node.staticInvokeType;
3617 DartType declaredType = node.function.staticType;
3618 if (invokeType is FunctionType && declaredType is FunctionType) {
3619 Iterable<DartType> typeArgs =
3620 FunctionTypeImpl.recoverTypeArguments(declaredType, invokeType);
3621 if (typeArgs.any((t) => t.isDynamic)) {
3622 // Issue an error depending on what we're trying to call.
3623 Expression function = node.function;
3624 if (function is Identifier) {
3625 Element element = function.staticElement;
3626 if (element is MethodElement) {
3627 _errorReporter.reportErrorForNode(
3628 StrongModeCode.IMPLICIT_DYNAMIC_METHOD,
3629 node.function,
3630 [element.displayName, element.typeParameters.join(', ')]);
3631 return;
3632 }
3633
3634 if (element is FunctionElement) {
3635 _errorReporter.reportErrorForNode(
3636 StrongModeCode.IMPLICIT_DYNAMIC_FUNCTION,
3637 node.function,
3638 [element.displayName, element.typeParameters.join(', ')]);
3639 return;
3640 }
3641 }
3642
3643 // The catch all case if neither of those matched.
3644 // For example, invoking a function expression.
3645 _errorReporter.reportErrorForNode(
3646 StrongModeCode.IMPLICIT_DYNAMIC_INVOKE,
3647 node.function,
3648 [declaredType]);
3649 }
3650 }
3651 }
3652
3653 void _checkForImplicitDynamicReturn(AstNode node, ExecutableElement element) {
3654 if (_options.implicitDynamic) {
3655 return;
3656 }
3657 if (element is PropertyAccessorElement && element.isSetter) {
3658 return;
3659 }
3660 if (element != null &&
3661 element.hasImplicitReturnType &&
3662 element.returnType.isDynamic) {
Leaf 2016/06/24 21:40:25 Can we trust returnType not to be null?
Jennifer Messerly 2016/06/27 18:38:17 I believe so, yes. Most of the methods in this fil
3663 _errorReporter.reportErrorForNode(
3664 StrongModeCode.IMPLICIT_DYNAMIC_RETURN, node, [element.displayName]);
3665 }
3666 }
3667
3668 void _checkForImplicitDynamicType(TypeName node) {
3669 if (_options.implicitDynamic ||
3670 node == null ||
3671 node.typeArguments != null) {
3672 return;
3673 }
3674 DartType type = node.type;
3675 if (type is ParameterizedType &&
3676 type.typeArguments.isNotEmpty &&
3677 type.typeArguments.any((t) => t.isDynamic)) {
3678 _errorReporter.reportErrorForNode(
3679 StrongModeCode.IMPLICIT_DYNAMIC_TYPE, node, [type]);
3680 }
3681 }
3682
3683 void _checkForImplicitDynamicTypedLiteral(TypedLiteral node) {
3684 if (_options.implicitDynamic || node.typeArguments != null) {
3685 return;
3686 }
3687 DartType type = node.staticType;
3688 // It's an error if either the key or value was inferred as dynamic.
3689 if (type is InterfaceType && type.typeArguments.any((t) => t.isDynamic)) {
3690 ErrorCode errorCode = node is ListLiteral
3691 ? StrongModeCode.IMPLICIT_DYNAMIC_LIST_LITERAL
3692 : StrongModeCode.IMPLICIT_DYNAMIC_MAP_LITERAL;
3693 _errorReporter.reportErrorForNode(errorCode, node);
3694 }
3695 }
3696
3541 /** 3697 /**
3542 * Verify that if the given [identifier] is part of a constructor initializer, 3698 * Verify that if the given [identifier] is part of a constructor initializer,
3543 * then it does not implicitly reference 'this' expression. 3699 * then it does not implicitly reference 'this' expression.
3544 * 3700 *
3545 * See [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER], and 3701 * See [CompileTimeErrorCode.IMPLICIT_THIS_REFERENCE_IN_INITIALIZER], and
3546 * [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC]. 3702 * [CompileTimeErrorCode.INSTANCE_MEMBER_ACCESS_FROM_STATIC].
3547 * TODO(scheglov) rename thid method 3703 * TODO(scheglov) rename thid method
3548 */ 3704 */
3549 void _checkForImplicitThisReferenceInInitializer( 3705 void _checkForImplicitThisReferenceInInitializer(
3550 SimpleIdentifier identifier) { 3706 SimpleIdentifier identifier) {
(...skipping 2756 matching lines...) Expand 10 before | Expand all | Expand 10 after
6307 class _InvocationCollector extends RecursiveAstVisitor { 6463 class _InvocationCollector extends RecursiveAstVisitor {
6308 final List<String> superCalls = <String>[]; 6464 final List<String> superCalls = <String>[];
6309 6465
6310 @override 6466 @override
6311 visitMethodInvocation(MethodInvocation node) { 6467 visitMethodInvocation(MethodInvocation node) {
6312 if (node.target is SuperExpression) { 6468 if (node.target is SuperExpression) {
6313 superCalls.add(node.methodName.name); 6469 superCalls.add(node.methodName.name);
6314 } 6470 }
6315 } 6471 }
6316 } 6472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698