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

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

Issue 2624283003: Revert "Add support for generic function type syntax, part 1" (TBR) (Closed)
Patch Set: Created 3 years, 11 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 750 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 _hiddenElements.declare(functionElement); 761 _hiddenElements.declare(functionElement);
762 } 762 }
763 ExecutableElement outerFunction = _enclosingFunction; 763 ExecutableElement outerFunction = _enclosingFunction;
764 try { 764 try {
765 SimpleIdentifier identifier = node.name; 765 SimpleIdentifier identifier = node.name;
766 String methodName = ""; 766 String methodName = "";
767 if (identifier != null) { 767 if (identifier != null) {
768 methodName = identifier.name; 768 methodName = identifier.name;
769 } 769 }
770 _enclosingFunction = functionElement; 770 _enclosingFunction = functionElement;
771 TypeAnnotation returnType = node.returnType; 771 TypeName returnType = node.returnType;
772 if (node.isSetter || node.isGetter) { 772 if (node.isSetter || node.isGetter) {
773 _checkForMismatchedAccessorTypes(node, methodName); 773 _checkForMismatchedAccessorTypes(node, methodName);
774 if (node.isSetter) { 774 if (node.isSetter) {
775 FunctionExpression functionExpression = node.functionExpression; 775 FunctionExpression functionExpression = node.functionExpression;
776 if (functionExpression != null) { 776 if (functionExpression != null) {
777 _checkForWrongNumberOfParametersForSetter( 777 _checkForWrongNumberOfParametersForSetter(
778 identifier, functionExpression.parameters); 778 identifier, functionExpression.parameters);
779 } 779 }
780 _checkForNonVoidReturnTypeForSetter(returnType); 780 _checkForNonVoidReturnTypeForSetter(returnType);
781 } 781 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 [node.identifier]); 855 [node.identifier]);
856 } 856 }
857 } 857 }
858 return super.visitFunctionTypedFormalParameter(node); 858 return super.visitFunctionTypedFormalParameter(node);
859 } finally { 859 } finally {
860 _isInFunctionTypedFormalParameter = old; 860 _isInFunctionTypedFormalParameter = old;
861 } 861 }
862 } 862 }
863 863
864 @override 864 @override
865 Object visitGenericFunctionType(GenericFunctionType node) {
866 throw new StateError(
867 'Support for generic function types is not yet implemented');
868 // return super.visitGenericFunctionType(node);
869 }
870
871 @override
872 Object visitGenericTypeAlias(GenericTypeAlias node) {
873 throw new StateError(
874 'Support for generic type aliases is not yet implemented');
875 // return super.visitGenericTypeAlias(node);
876 }
877
878 @override
879 Object visitIfStatement(IfStatement node) { 865 Object visitIfStatement(IfStatement node) {
880 _checkForNonBoolCondition(node.condition); 866 _checkForNonBoolCondition(node.condition);
881 return super.visitIfStatement(node); 867 return super.visitIfStatement(node);
882 } 868 }
883 869
884 @override 870 @override
885 Object visitImplementsClause(ImplementsClause node) { 871 Object visitImplementsClause(ImplementsClause node) {
886 node.interfaces.forEach(_checkForImplicitDynamicType); 872 node.interfaces.forEach(_checkForImplicitDynamicType);
887 return super.visitImplementsClause(node); 873 return super.visitImplementsClause(node);
888 } 874 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 _checkForTypeAnnotationDeferredClass(node.type); 924 _checkForTypeAnnotationDeferredClass(node.type);
939 _checkForTypeAnnotationGenericFunctionParameter(node.type); 925 _checkForTypeAnnotationGenericFunctionParameter(node.type);
940 return super.visitIsExpression(node); 926 return super.visitIsExpression(node);
941 } 927 }
942 928
943 @override 929 @override
944 Object visitListLiteral(ListLiteral node) { 930 Object visitListLiteral(ListLiteral node) {
945 TypeArgumentList typeArguments = node.typeArguments; 931 TypeArgumentList typeArguments = node.typeArguments;
946 if (typeArguments != null) { 932 if (typeArguments != null) {
947 if (!_options.strongMode && node.constKeyword != null) { 933 if (!_options.strongMode && node.constKeyword != null) {
948 NodeList<TypeAnnotation> arguments = typeArguments.arguments; 934 NodeList<TypeName> arguments = typeArguments.arguments;
949 if (arguments.isNotEmpty) { 935 if (arguments.isNotEmpty) {
950 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, 936 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
951 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST); 937 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
952 } 938 }
953 } 939 }
954 _checkForExpectedOneListTypeArgument(node, typeArguments); 940 _checkForExpectedOneListTypeArgument(node, typeArguments);
955 } 941 }
956 _checkForImplicitDynamicTypedLiteral(node); 942 _checkForImplicitDynamicTypedLiteral(node);
957 _checkForListElementTypeNotAssignable(node); 943 _checkForListElementTypeNotAssignable(node);
958 return super.visitListLiteral(node); 944 return super.visitListLiteral(node);
959 } 945 }
960 946
961 @override 947 @override
962 Object visitMapLiteral(MapLiteral node) { 948 Object visitMapLiteral(MapLiteral node) {
963 TypeArgumentList typeArguments = node.typeArguments; 949 TypeArgumentList typeArguments = node.typeArguments;
964 if (typeArguments != null) { 950 if (typeArguments != null) {
965 NodeList<TypeAnnotation> arguments = typeArguments.arguments; 951 NodeList<TypeName> arguments = typeArguments.arguments;
966 if (!_options.strongMode && arguments.isNotEmpty) { 952 if (!_options.strongMode && arguments.isNotEmpty) {
967 if (node.constKeyword != null) { 953 if (node.constKeyword != null) {
968 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments, 954 _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
969 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP); 955 CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP);
970 } 956 }
971 } 957 }
972 _checkExpectedTwoMapTypeArguments(typeArguments); 958 _checkExpectedTwoMapTypeArguments(typeArguments);
973 } 959 }
974 _checkForImplicitDynamicTypedLiteral(node); 960 _checkForImplicitDynamicTypedLiteral(node);
975 _checkForMapTypeNotAssignable(node); 961 _checkForMapTypeNotAssignable(node);
976 _checkForNonConstMapAsExpressionStatement(node); 962 _checkForNonConstMapAsExpressionStatement(node);
977 return super.visitMapLiteral(node); 963 return super.visitMapLiteral(node);
978 } 964 }
979 965
980 @override 966 @override
981 Object visitMethodDeclaration(MethodDeclaration node) { 967 Object visitMethodDeclaration(MethodDeclaration node) {
982 ExecutableElement previousFunction = _enclosingFunction; 968 ExecutableElement previousFunction = _enclosingFunction;
983 try { 969 try {
984 _isInStaticMethod = node.isStatic; 970 _isInStaticMethod = node.isStatic;
985 _enclosingFunction = node.element; 971 _enclosingFunction = node.element;
986 SimpleIdentifier identifier = node.name; 972 SimpleIdentifier identifier = node.name;
987 String methodName = ""; 973 String methodName = "";
988 if (identifier != null) { 974 if (identifier != null) {
989 methodName = identifier.name; 975 methodName = identifier.name;
990 } 976 }
991 TypeAnnotation returnType = node.returnType; 977 TypeName returnTypeName = node.returnType;
992 if (node.isSetter || node.isGetter) { 978 if (node.isSetter || node.isGetter) {
993 _checkForMismatchedAccessorTypes(node, methodName); 979 _checkForMismatchedAccessorTypes(node, methodName);
994 } 980 }
995 if (node.isGetter) { 981 if (node.isGetter) {
996 _checkForVoidReturnType(node); 982 _checkForVoidReturnType(node);
997 _checkForConflictingStaticGetterAndInstanceSetter(node); 983 _checkForConflictingStaticGetterAndInstanceSetter(node);
998 } else if (node.isSetter) { 984 } else if (node.isSetter) {
999 _checkForInvalidModifierOnBody( 985 _checkForInvalidModifierOnBody(
1000 node.body, CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER); 986 node.body, CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER);
1001 _checkForWrongNumberOfParametersForSetter(node.name, node.parameters); 987 _checkForWrongNumberOfParametersForSetter(node.name, node.parameters);
1002 _checkForNonVoidReturnTypeForSetter(returnType); 988 _checkForNonVoidReturnTypeForSetter(returnTypeName);
1003 _checkForConflictingStaticSetterAndInstanceMember(node); 989 _checkForConflictingStaticSetterAndInstanceMember(node);
1004 } else if (node.isOperator) { 990 } else if (node.isOperator) {
1005 _checkForOptionalParameterInOperator(node); 991 _checkForOptionalParameterInOperator(node);
1006 _checkForWrongNumberOfParametersForOperator(node); 992 _checkForWrongNumberOfParametersForOperator(node);
1007 _checkForNonVoidReturnTypeForOperator(node); 993 _checkForNonVoidReturnTypeForOperator(node);
1008 } 994 }
1009 _checkForConcreteClassWithAbstractMember(node); 995 _checkForConcreteClassWithAbstractMember(node);
1010 _checkForAllInvalidOverrideErrorCodesForMethod(node); 996 _checkForAllInvalidOverrideErrorCodesForMethod(node);
1011 _checkForTypeAnnotationDeferredClass(returnType); 997 _checkForTypeAnnotationDeferredClass(returnTypeName);
1012 _checkForIllegalReturnType(returnType); 998 _checkForIllegalReturnType(returnTypeName);
1013 _checkForImplicitDynamicReturn(node, node.element); 999 _checkForImplicitDynamicReturn(node.name, node.element);
1014 _checkForMustCallSuper(node); 1000 _checkForMustCallSuper(node);
1015 return super.visitMethodDeclaration(node); 1001 return super.visitMethodDeclaration(node);
1016 } finally { 1002 } finally {
1017 _enclosingFunction = previousFunction; 1003 _enclosingFunction = previousFunction;
1018 _isInStaticMethod = false; 1004 _isInStaticMethod = false;
1019 } 1005 }
1020 } 1006 }
1021 1007
1022 @override 1008 @override
1023 Object visitMethodInvocation(MethodInvocation node) { 1009 Object visitMethodInvocation(MethodInvocation node) {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 } 1180 }
1195 1181
1196 @override 1182 @override
1197 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) { 1183 Object visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
1198 _checkForFinalNotInitialized(node.variables); 1184 _checkForFinalNotInitialized(node.variables);
1199 return super.visitTopLevelVariableDeclaration(node); 1185 return super.visitTopLevelVariableDeclaration(node);
1200 } 1186 }
1201 1187
1202 @override 1188 @override
1203 Object visitTypeArgumentList(TypeArgumentList node) { 1189 Object visitTypeArgumentList(TypeArgumentList node) {
1204 NodeList<TypeAnnotation> list = node.arguments; 1190 NodeList<TypeName> list = node.arguments;
1205 for (TypeAnnotation type in list) { 1191 for (TypeName typeName in list) {
1206 _checkForTypeAnnotationDeferredClass(type); 1192 _checkForTypeAnnotationDeferredClass(typeName);
1207 } 1193 }
1208 return super.visitTypeArgumentList(node); 1194 return super.visitTypeArgumentList(node);
1209 } 1195 }
1210 1196
1211 @override 1197 @override
1212 Object visitTypeName(TypeName node) { 1198 Object visitTypeName(TypeName node) {
1213 _checkForTypeArgumentNotMatchingBounds(node); 1199 _checkForTypeArgumentNotMatchingBounds(node);
1214 _checkForTypeParameterReferencedByStatic(node); 1200 _checkForTypeParameterReferencedByStatic(node);
1215 return super.visitTypeName(node); 1201 return super.visitTypeName(node);
1216 } 1202 }
(...skipping 2010 matching lines...) Expand 10 before | Expand all | Expand 10 after
3227 */ 3213 */
3228 void _checkForConstWithNonConst(InstanceCreationExpression expression) { 3214 void _checkForConstWithNonConst(InstanceCreationExpression expression) {
3229 ConstructorElement constructorElement = expression.staticElement; 3215 ConstructorElement constructorElement = expression.staticElement;
3230 if (constructorElement != null && !constructorElement.isConst) { 3216 if (constructorElement != null && !constructorElement.isConst) {
3231 _errorReporter.reportErrorForNode( 3217 _errorReporter.reportErrorForNode(
3232 CompileTimeErrorCode.CONST_WITH_NON_CONST, expression); 3218 CompileTimeErrorCode.CONST_WITH_NON_CONST, expression);
3233 } 3219 }
3234 } 3220 }
3235 3221
3236 /** 3222 /**
3237 * Verify that the given [type] does not reference any type parameters. 3223 * Verify that the given [typeName] does not reference any type parameters.
3238 * 3224 *
3239 * See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS]. 3225 * See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS].
3240 */ 3226 */
3241 void _checkForConstWithTypeParameters(TypeAnnotation type) { 3227 void _checkForConstWithTypeParameters(TypeName typeName) {
3242 // something wrong with AST 3228 // something wrong with AST
3243 if (type is! TypeName) { 3229 if (typeName == null) {
3244 return; 3230 return;
3245 } 3231 }
3246 TypeName typeName = type;
3247 Identifier name = typeName.name; 3232 Identifier name = typeName.name;
3248 if (name == null) { 3233 if (name == null) {
3249 return; 3234 return;
3250 } 3235 }
3251 // should not be a type parameter 3236 // should not be a type parameter
3252 if (name.staticElement is TypeParameterElement) { 3237 if (name.staticElement is TypeParameterElement) {
3253 _errorReporter.reportErrorForNode( 3238 _errorReporter.reportErrorForNode(
3254 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, name); 3239 CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS, name);
3255 } 3240 }
3256 // check type arguments 3241 // check type arguments
3257 TypeArgumentList typeArguments = typeName.typeArguments; 3242 TypeArgumentList typeArguments = typeName.typeArguments;
3258 if (typeArguments != null) { 3243 if (typeArguments != null) {
3259 for (TypeAnnotation argument in typeArguments.arguments) { 3244 for (TypeName argument in typeArguments.arguments) {
3260 _checkForConstWithTypeParameters(argument); 3245 _checkForConstWithTypeParameters(argument);
3261 } 3246 }
3262 } 3247 }
3263 } 3248 }
3264 3249
3265 /** 3250 /**
3266 * Verify that if the given 'const' instance creation [expression] is being 3251 * Verify that if the given 'const' instance creation [expression] is being
3267 * invoked on the resolved constructor. The [constructorName] is the 3252 * invoked on the resolved constructor. The [constructorName] is the
3268 * constructor name, always non-`null`. The [typeName] is the name of the type 3253 * constructor name, always non-`null`. The [typeName] is the name of the type
3269 * defining the constructor, always non-`null`. 3254 * defining the constructor, always non-`null`.
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
3814 _checkForFinalNotInitialized(classMember.fields); 3799 _checkForFinalNotInitialized(classMember.fields);
3815 } 3800 }
3816 } 3801 }
3817 } 3802 }
3818 3803
3819 /** 3804 /**
3820 * If the current function is async, async*, or sync*, verify that its 3805 * If the current function is async, async*, or sync*, verify that its
3821 * declared return type is assignable to Future, Stream, or Iterable, 3806 * declared return type is assignable to Future, Stream, or Iterable,
3822 * respectively. If not, report the error using [returnType]. 3807 * respectively. If not, report the error using [returnType].
3823 */ 3808 */
3824 void _checkForIllegalReturnType(TypeAnnotation returnType) { 3809 void _checkForIllegalReturnType(TypeName returnType) {
3825 if (returnType == null) { 3810 if (returnType == null) {
3826 // No declared return type, so the return type must be dynamic, which is 3811 // No declared return type, so the return type must be dynamic, which is
3827 // assignable to everything. 3812 // assignable to everything.
3828 return; 3813 return;
3829 } 3814 }
3830 if (_enclosingFunction.isAsynchronous) { 3815 if (_enclosingFunction.isAsynchronous) {
3831 if (_enclosingFunction.isGenerator) { 3816 if (_enclosingFunction.isGenerator) {
3832 _checkForIllegalReturnTypeCode( 3817 _checkForIllegalReturnTypeCode(
3833 returnType, 3818 returnType,
3834 _typeProvider.streamDynamicType, 3819 _typeProvider.streamDynamicType,
(...skipping 12 matching lines...) Expand all
3847 } 3832 }
3848 } 3833 }
3849 3834
3850 /** 3835 /**
3851 * If the current function is async, async*, or sync*, verify that its 3836 * If the current function is async, async*, or sync*, verify that its
3852 * declared return type is assignable to Future, Stream, or Iterable, 3837 * declared return type is assignable to Future, Stream, or Iterable,
3853 * respectively. This is called by [_checkForIllegalReturnType] to check if 3838 * respectively. This is called by [_checkForIllegalReturnType] to check if
3854 * the declared [returnTypeName] is assignable to the required [expectedType] 3839 * the declared [returnTypeName] is assignable to the required [expectedType]
3855 * and if not report [errorCode]. 3840 * and if not report [errorCode].
3856 */ 3841 */
3857 void _checkForIllegalReturnTypeCode(TypeAnnotation returnTypeName, 3842 void _checkForIllegalReturnTypeCode(TypeName returnTypeName,
3858 DartType expectedType, StaticTypeWarningCode errorCode) { 3843 DartType expectedType, StaticTypeWarningCode errorCode) {
3859 DartType returnType = _enclosingFunction.returnType; 3844 DartType returnType = _enclosingFunction.returnType;
3860 if (_options.strongMode) { 3845 if (_options.strongMode) {
3861 // 3846 //
3862 // When checking an async/sync*/async* method, we know the exact type 3847 // When checking an async/sync*/async* method, we know the exact type
3863 // that will be returned (e.g. Future, Iterable, or Stream). 3848 // that will be returned (e.g. Future, Iterable, or Stream).
3864 // 3849 //
3865 // For example an `async` function body will return a `Future<T>` for 3850 // For example an `async` function body will return a `Future<T>` for
3866 // some `T` (possibly `dynamic`). 3851 // some `T` (possibly `dynamic`).
3867 // 3852 //
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
3994 return; 3979 return;
3995 } 3980 }
3996 if (element != null && 3981 if (element != null &&
3997 element.hasImplicitReturnType && 3982 element.hasImplicitReturnType &&
3998 element.returnType.isDynamic) { 3983 element.returnType.isDynamic) {
3999 _errorReporter.reportErrorForNode(StrongModeCode.IMPLICIT_DYNAMIC_RETURN, 3984 _errorReporter.reportErrorForNode(StrongModeCode.IMPLICIT_DYNAMIC_RETURN,
4000 functionName, [element.displayName]); 3985 functionName, [element.displayName]);
4001 } 3986 }
4002 } 3987 }
4003 3988
4004 void _checkForImplicitDynamicType(TypeAnnotation node) { 3989 void _checkForImplicitDynamicType(TypeName node) {
4005 if (_options.implicitDynamic || 3990 if (_options.implicitDynamic ||
4006 node == null || 3991 node == null ||
4007 (node is TypeName && node.typeArguments != null)) { 3992 node.typeArguments != null) {
4008 return; 3993 return;
4009 } 3994 }
4010 DartType type = node.type; 3995 DartType type = node.type;
4011 if (type is ParameterizedType && 3996 if (type is ParameterizedType &&
4012 type.typeArguments.isNotEmpty && 3997 type.typeArguments.isNotEmpty &&
4013 type.typeArguments.any((t) => t.isDynamic)) { 3998 type.typeArguments.any((t) => t.isDynamic)) {
4014 _errorReporter.reportErrorForNode( 3999 _errorReporter.reportErrorForNode(
4015 StrongModeCode.IMPLICIT_DYNAMIC_TYPE, node, [type]); 4000 StrongModeCode.IMPLICIT_DYNAMIC_TYPE, node, [type]);
4016 } 4001 }
4017 } 4002 }
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
4465 } 4450 }
4466 } 4451 }
4467 4452
4468 /** 4453 /**
4469 * Checks to ensure that the given list of type [arguments] does not have a 4454 * Checks to ensure that the given list of type [arguments] does not have a
4470 * type parameter as a type argument. The [errorCode] is either 4455 * type parameter as a type argument. The [errorCode] is either
4471 * [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST] or 4456 * [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST] or
4472 * [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP]. 4457 * [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP].
4473 */ 4458 */
4474 void _checkForInvalidTypeArgumentInConstTypedLiteral( 4459 void _checkForInvalidTypeArgumentInConstTypedLiteral(
4475 NodeList<TypeAnnotation> arguments, ErrorCode errorCode) { 4460 NodeList<TypeName> arguments, ErrorCode errorCode) {
4476 for (TypeAnnotation type in arguments) { 4461 for (TypeName typeName in arguments) {
4477 if (type is TypeName && type.type is TypeParameterType) { 4462 if (typeName.type is TypeParameterType) {
4478 _errorReporter.reportErrorForNode(errorCode, type, [type.name]); 4463 _errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name]);
4479 } 4464 }
4480 } 4465 }
4481 } 4466 }
4482 4467
4483 /** 4468 /**
4484 * Verify that the elements given list [literal] are subtypes of the list's 4469 * Verify that the elements given list [literal] are subtypes of the list's
4485 * static type. 4470 * static type.
4486 * 4471 *
4487 * See [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], and 4472 * See [CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE], and
4488 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE]. 4473 * [StaticWarningCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE].
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
5149 * 5134 *
5150 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR]. 5135 * See [StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR].
5151 */ 5136 */
5152 void _checkForNonVoidReturnTypeForOperator(MethodDeclaration declaration) { 5137 void _checkForNonVoidReturnTypeForOperator(MethodDeclaration declaration) {
5153 // check that []= operator 5138 // check that []= operator
5154 SimpleIdentifier name = declaration.name; 5139 SimpleIdentifier name = declaration.name;
5155 if (name.name != "[]=") { 5140 if (name.name != "[]=") {
5156 return; 5141 return;
5157 } 5142 }
5158 // check return type 5143 // check return type
5159 TypeAnnotation annotation = declaration.returnType; 5144 TypeName typeName = declaration.returnType;
5160 if (annotation != null) { 5145 if (typeName != null) {
5161 DartType type = annotation.type; 5146 DartType type = typeName.type;
5162 if (type != null && !type.isVoid) { 5147 if (type != null && !type.isVoid) {
5163 _errorReporter.reportErrorForNode( 5148 _errorReporter.reportErrorForNode(
5164 StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR, annotation); 5149 StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR, typeName);
5165 } 5150 }
5166 } 5151 }
5167 } 5152 }
5168 5153
5169 /** 5154 /**
5170 * Verify the [typeName], used as the return type of a setter, is valid 5155 * Verify the [typeName], used as the return type of a setter, is valid
5171 * (either `null` or the type 'void'). 5156 * (either `null` or the type 'void').
5172 * 5157 *
5173 * See [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER]. 5158 * See [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER].
5174 */ 5159 */
5175 void _checkForNonVoidReturnTypeForSetter(TypeAnnotation typeName) { 5160 void _checkForNonVoidReturnTypeForSetter(TypeName typeName) {
5176 if (typeName != null) { 5161 if (typeName != null) {
5177 DartType type = typeName.type; 5162 DartType type = typeName.type;
5178 if (type != null && !type.isVoid) { 5163 if (type != null && !type.isVoid) {
5179 _errorReporter.reportErrorForNode( 5164 _errorReporter.reportErrorForNode(
5180 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, typeName); 5165 StaticWarningCode.NON_VOID_RETURN_FOR_SETTER, typeName);
5181 } 5166 }
5182 } 5167 }
5183 } 5168 }
5184 5169
5185 /** 5170 /**
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
5587 _errorReporter.reportErrorForNode( 5572 _errorReporter.reportErrorForNode(
5588 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, alias); 5573 CompileTimeErrorCode.TYPE_ALIAS_CANNOT_REFERENCE_ITSELF, alias);
5589 } 5574 }
5590 } 5575 }
5591 5576
5592 /** 5577 /**
5593 * Verify that the given type [name] is not a deferred type. 5578 * Verify that the given type [name] is not a deferred type.
5594 * 5579 *
5595 * See [StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS]. 5580 * See [StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS].
5596 */ 5581 */
5597 void _checkForTypeAnnotationDeferredClass(TypeAnnotation type) { 5582 void _checkForTypeAnnotationDeferredClass(TypeName name) {
5598 if (type is TypeName && type.isDeferred) { 5583 if (name != null && name.isDeferred) {
5599 _errorReporter.reportErrorForNode( 5584 _errorReporter.reportErrorForNode(
5600 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, type, [type.name]); 5585 StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, name, [name.name]);
5601 } 5586 }
5602 } 5587 }
5603 5588
5604 /** 5589 /**
5605 * Verify that the given type [name] is not a type parameter in a generic 5590 * Verify that the given type [name] is not a type parameter in a generic
5606 * method. 5591 * method.
5607 * 5592 *
5608 * See [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER]. 5593 * See [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER].
5609 */ 5594 */
5610 void _checkForTypeAnnotationGenericFunctionParameter(TypeAnnotation type) { 5595 void _checkForTypeAnnotationGenericFunctionParameter(TypeName typeName) {
5611 if (type is TypeName) { 5596 if (typeName == null) {
5612 Identifier name = type.name; 5597 return;
5613 if (name is SimpleIdentifier) { 5598 }
5614 Element element = name.staticElement; 5599 Identifier name = typeName.name;
5615 if (element is TypeParameterElement && 5600 if (name is SimpleIdentifier) {
5616 element.enclosingElement is ExecutableElement) { 5601 Element element = name.staticElement;
5617 _errorReporter.reportErrorForNode( 5602 if (element is TypeParameterElement &&
5618 StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER, 5603 element.enclosingElement is ExecutableElement) {
5619 name, 5604 _errorReporter.reportErrorForNode(
5620 [name.name]); 5605 StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER,
5621 } 5606 name,
5607 [name.name]);
5622 } 5608 }
5623 } 5609 }
5624 } 5610 }
5625 5611
5626 /** 5612 /**
5627 * Verify that the type arguments in the given [typeName] are all within 5613 * Verify that the type arguments in the given [typeName] are all within
5628 * their bounds. 5614 * their bounds.
5629 * 5615 *
5630 * See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]. 5616 * See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
5631 */ 5617 */
5632 void _checkForTypeArgumentNotMatchingBounds(TypeName typeName) { 5618 void _checkForTypeArgumentNotMatchingBounds(TypeName typeName) {
5633 if (typeName.typeArguments == null) { 5619 if (typeName.typeArguments == null) {
5634 return; 5620 return;
5635 } 5621 }
5636 // prepare Type 5622 // prepare Type
5637 DartType type = typeName.type; 5623 DartType type = typeName.type;
5638 if (type == null) { 5624 if (type == null) {
5639 return; 5625 return;
5640 } 5626 }
5641 Element element = type.element; 5627 Element element = type.element;
5642 if (element is ClassElement) { 5628 if (element is ClassElement) {
5643 // prepare type parameters 5629 // prepare type parameters
5644 List<TypeParameterElement> parameterElements = element.typeParameters; 5630 List<TypeParameterElement> parameterElements = element.typeParameters;
5645 List<DartType> parameterTypes = element.type.typeArguments; 5631 List<DartType> parameterTypes = element.type.typeArguments;
5646 List<DartType> arguments = (type as ParameterizedType).typeArguments; 5632 List<DartType> arguments = (type as ParameterizedType).typeArguments;
5647 // iterate over each bounded type parameter and corresponding argument 5633 // iterate over each bounded type parameter and corresponding argument
5648 NodeList<TypeAnnotation> argumentNodes = typeName.typeArguments.arguments; 5634 NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
5649 int loopThroughIndex = 5635 int loopThroughIndex =
5650 math.min(argumentNodes.length, parameterElements.length); 5636 math.min(typeNameArgList.length, parameterElements.length);
5651 bool shouldSubstitute = 5637 bool shouldSubstitute =
5652 arguments.length != 0 && arguments.length == parameterTypes.length; 5638 arguments.length != 0 && arguments.length == parameterTypes.length;
5653 for (int i = 0; i < loopThroughIndex; i++) { 5639 for (int i = 0; i < loopThroughIndex; i++) {
5654 TypeAnnotation argumentNode = argumentNodes[i]; 5640 TypeName argTypeName = typeNameArgList[i];
5655 DartType argType = argumentNode.type; 5641 DartType argType = argTypeName.type;
5656 DartType boundType = parameterElements[i].bound; 5642 DartType boundType = parameterElements[i].bound;
5657 if (argType != null && boundType != null) { 5643 if (argType != null && boundType != null) {
5658 if (shouldSubstitute) { 5644 if (shouldSubstitute) {
5659 boundType = boundType.substitute2(arguments, parameterTypes); 5645 boundType = boundType.substitute2(arguments, parameterTypes);
5660 } 5646 }
5661 if (!_typeSystem.isSubtypeOf(argType, boundType)) { 5647 if (!_typeSystem.isSubtypeOf(argType, boundType)) {
5662 ErrorCode errorCode; 5648 ErrorCode errorCode;
5663 if (_isInConstInstanceCreation) { 5649 if (_isInConstInstanceCreation) {
5664 errorCode = 5650 errorCode =
5665 CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 5651 CompileTimeErrorCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
5666 } else { 5652 } else {
5667 errorCode = 5653 errorCode =
5668 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS; 5654 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
5669 } 5655 }
5670 _errorReporter.reportTypeErrorForNode( 5656 _errorReporter.reportTypeErrorForNode(
5671 errorCode, argumentNode, [argType, boundType]); 5657 errorCode, argTypeName, [argType, boundType]);
5672 } 5658 }
5673 } 5659 }
5674 } 5660 }
5675 } 5661 }
5676 } 5662 }
5677 5663
5678 /** 5664 /**
5679 * Check whether the given type [name] is a type parameter being used to 5665 * Check whether the given type [name] is a type parameter being used to
5680 * define a static member. 5666 * define a static member.
5681 * 5667 *
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
5871 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo des) 5857 // // (Either here or in ErrorVerifier.checkForAllFinalInitializedErrorCo des)
5872 // } 5858 // }
5873 } 5859 }
5874 5860
5875 /** 5861 /**
5876 * Verify that the given [getter] does not have a return type of 'void'. 5862 * Verify that the given [getter] does not have a return type of 'void'.
5877 * 5863 *
5878 * See [StaticWarningCode.VOID_RETURN_FOR_GETTER]. 5864 * See [StaticWarningCode.VOID_RETURN_FOR_GETTER].
5879 */ 5865 */
5880 void _checkForVoidReturnType(MethodDeclaration getter) { 5866 void _checkForVoidReturnType(MethodDeclaration getter) {
5881 TypeAnnotation returnType = getter.returnType; 5867 TypeName returnType = getter.returnType;
5882 if (returnType is TypeName && returnType.name.name == "void") { 5868 if (returnType == null || returnType.name.name != "void") {
5883 _errorReporter.reportErrorForNode( 5869 return;
5884 StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType);
5885 } 5870 }
5871 _errorReporter.reportErrorForNode(
5872 StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType);
5886 } 5873 }
5887 5874
5888 /** 5875 /**
5889 * Verify the given operator-method [declaration], has correct number of 5876 * Verify the given operator-method [declaration], has correct number of
5890 * parameters. 5877 * parameters.
5891 * 5878 *
5892 * This method assumes that the method declaration was tested to be an 5879 * This method assumes that the method declaration was tested to be an
5893 * operator declaration before being called. 5880 * operator declaration before being called.
5894 * 5881 *
5895 * See [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR]. 5882 * See [CompileTimeErrorCode.WRONG_NUMBER_OF_PARAMETERS_FOR_OPERATOR].
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
6083 * Verify that the given [typeArguments] are all within their bounds, as 6070 * Verify that the given [typeArguments] are all within their bounds, as
6084 * defined by the given [element]. 6071 * defined by the given [element].
6085 * 6072 *
6086 * See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS]. 6073 * See [StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS].
6087 */ 6074 */
6088 void _checkTypeArguments(Element element, TypeArgumentList typeArguments, 6075 void _checkTypeArguments(Element element, TypeArgumentList typeArguments,
6089 [DartType targetType]) { 6076 [DartType targetType]) {
6090 if (element == null || typeArguments == null) { 6077 if (element == null || typeArguments == null) {
6091 return; 6078 return;
6092 } 6079 }
6093 void reportError(TypeAnnotation argument, DartType argumentType, 6080 void reportError(
6094 DartType parameterType) { 6081 TypeName argument, DartType argumentType, DartType parameterType) {
6095 _errorReporter.reportTypeErrorForNode( 6082 _errorReporter.reportTypeErrorForNode(
6096 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS, 6083 StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
6097 argument, 6084 argument,
6098 [argumentType, parameterType]); 6085 [argumentType, parameterType]);
6099 } 6086 }
6100 6087
6101 if (element is FunctionTypedElement) { 6088 if (element is FunctionTypedElement) {
6102 _checkTypeArgumentsAgainstBounds( 6089 _checkTypeArgumentsAgainstBounds(
6103 element.typeParameters, typeArguments, targetType, reportError); 6090 element.typeParameters, typeArguments, targetType, reportError);
6104 } else if (element is ClassElement) { 6091 } else if (element is ClassElement) {
6105 _checkTypeArgumentsAgainstBounds( 6092 _checkTypeArgumentsAgainstBounds(
6106 element.typeParameters, typeArguments, targetType, reportError); 6093 element.typeParameters, typeArguments, targetType, reportError);
6107 } else if (element is ParameterElement || element is LocalVariableElement) { 6094 } else if (element is ParameterElement || element is LocalVariableElement) {
6108 // TODO(brianwilkerson) Implement this case 6095 // TODO(brianwilkerson) Implement this case
6109 } else { 6096 } else {
6110 print('Unhandled element type: ${element.runtimeType}'); 6097 print('Unhandled element type: ${element.runtimeType}');
6111 } 6098 }
6112 } 6099 }
6113 6100
6114 void _checkTypeArgumentsAgainstBounds( 6101 void _checkTypeArgumentsAgainstBounds(
6115 List<TypeParameterElement> typeParameters, 6102 List<TypeParameterElement> typeParameters,
6116 TypeArgumentList typeArgumentList, 6103 TypeArgumentList typeArgumentList,
6117 DartType targetType, 6104 DartType targetType,
6118 void reportError(TypeAnnotation argument, DartType argumentType, 6105 void reportError(
6119 DartType parameterType)) { 6106 TypeName argument, DartType argumentType, DartType parameterType)) {
6120 NodeList<TypeAnnotation> typeArguments = typeArgumentList.arguments; 6107 NodeList<TypeName> typeArguments = typeArgumentList.arguments;
6121 int argumentsLength = typeArguments.length; 6108 int argumentsLength = typeArguments.length;
6122 int maxIndex = math.min(typeParameters.length, argumentsLength); 6109 int maxIndex = math.min(typeParameters.length, argumentsLength);
6123 6110
6124 bool shouldSubstitute = 6111 bool shouldSubstitute =
6125 argumentsLength != 0 && argumentsLength == typeParameters.length; 6112 argumentsLength != 0 && argumentsLength == typeParameters.length;
6126 List<DartType> argumentTypes = shouldSubstitute 6113 List<DartType> argumentTypes = shouldSubstitute
6127 ? typeArguments.map((TypeAnnotation type) => type.type).toList() 6114 ? typeArguments.map((TypeName typeName) => typeName.type).toList()
6128 : null; 6115 : null;
6129 List<DartType> parameterTypes = shouldSubstitute 6116 List<DartType> parameterTypes = shouldSubstitute
6130 ? typeParameters 6117 ? typeParameters
6131 .map((TypeParameterElement element) => element.type) 6118 .map((TypeParameterElement element) => element.type)
6132 .toList() 6119 .toList()
6133 : null; 6120 : null;
6134 List<DartType> targetTypeParameterTypes = null; 6121 List<DartType> targetTypeParameterTypes = null;
6135 for (int i = 0; i < maxIndex; i++) { 6122 for (int i = 0; i < maxIndex; i++) {
6136 TypeAnnotation argument = typeArguments[i]; 6123 TypeName argTypeName = typeArguments[i];
6137 DartType argType = argument.type; 6124 DartType argType = argTypeName.type;
6138 DartType boundType = typeParameters[i].bound; 6125 DartType boundType = typeParameters[i].bound;
6139 if (argType != null && boundType != null) { 6126 if (argType != null && boundType != null) {
6140 if (targetType is ParameterizedType) { 6127 if (targetType is ParameterizedType) {
6141 if (targetTypeParameterTypes == null) { 6128 if (targetTypeParameterTypes == null) {
6142 targetTypeParameterTypes = targetType.typeParameters 6129 targetTypeParameterTypes = targetType.typeParameters
6143 .map((TypeParameterElement element) => element.type) 6130 .map((TypeParameterElement element) => element.type)
6144 .toList(); 6131 .toList();
6145 } 6132 }
6146 boundType = boundType.substitute2( 6133 boundType = boundType.substitute2(
6147 targetType.typeArguments, targetTypeParameterTypes); 6134 targetType.typeArguments, targetTypeParameterTypes);
6148 } 6135 }
6149 if (shouldSubstitute) { 6136 if (shouldSubstitute) {
6150 boundType = boundType.substitute2(argumentTypes, parameterTypes); 6137 boundType = boundType.substitute2(argumentTypes, parameterTypes);
6151 } 6138 }
6152 if (!_typeSystem.isSubtypeOf(argType, boundType)) { 6139 if (!_typeSystem.isSubtypeOf(argType, boundType)) {
6153 reportError(argument, argType, boundType); 6140 reportError(argTypeName, argType, boundType);
6154 } 6141 }
6155 } 6142 }
6156 } 6143 }
6157 } 6144 }
6158 6145
6159 DartType _computeReturnTypeForMethod(Expression returnExpression) { 6146 DartType _computeReturnTypeForMethod(Expression returnExpression) {
6160 // This method should never be called for generators, since generators are 6147 // This method should never be called for generators, since generators are
6161 // never allowed to contain return statements with expressions. 6148 // never allowed to contain return statements with expressions.
6162 assert(!_inGenerator); 6149 assert(!_inGenerator);
6163 if (returnExpression == null) { 6150 if (returnExpression == null) {
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after
7006 class _InvocationCollector extends RecursiveAstVisitor { 6993 class _InvocationCollector extends RecursiveAstVisitor {
7007 final List<String> superCalls = <String>[]; 6994 final List<String> superCalls = <String>[];
7008 6995
7009 @override 6996 @override
7010 visitMethodInvocation(MethodInvocation node) { 6997 visitMethodInvocation(MethodInvocation node) {
7011 if (node.target is SuperExpression) { 6998 if (node.target is SuperExpression) {
7012 superCalls.add(node.methodName.name); 6999 superCalls.add(node.methodName.name);
7013 } 7000 }
7014 } 7001 }
7015 } 7002 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/generated/element_resolver.dart ('k') | pkg/analyzer/lib/src/generated/resolver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698