| Index: pkg/analyzer/lib/src/generated/error_verifier.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
|
| index dff34027eadeec61808fa934d7b87999dd391743..96a010a9b3aee0a7ae44a54fbe4e39267cb1cb8c 100644
|
| --- a/pkg/analyzer/lib/src/generated/error_verifier.dart
|
| +++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
|
| @@ -768,7 +768,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| methodName = identifier.name;
|
| }
|
| _enclosingFunction = functionElement;
|
| - TypeName returnType = node.returnType;
|
| + TypeAnnotation returnType = node.returnType;
|
| if (node.isSetter || node.isGetter) {
|
| _checkForMismatchedAccessorTypes(node, methodName);
|
| if (node.isSetter) {
|
| @@ -862,6 +862,20 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| }
|
|
|
| @override
|
| + Object visitGenericFunctionType(GenericFunctionType node) {
|
| + throw new StateError(
|
| + 'Support for generic function types is not yet implemented');
|
| +// return super.visitGenericFunctionType(node);
|
| + }
|
| +
|
| + @override
|
| + Object visitGenericTypeAlias(GenericTypeAlias node) {
|
| + throw new StateError(
|
| + 'Support for generic type aliases is not yet implemented');
|
| +// return super.visitGenericTypeAlias(node);
|
| + }
|
| +
|
| + @override
|
| Object visitIfStatement(IfStatement node) {
|
| _checkForNonBoolCondition(node.condition);
|
| return super.visitIfStatement(node);
|
| @@ -931,7 +945,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| TypeArgumentList typeArguments = node.typeArguments;
|
| if (typeArguments != null) {
|
| if (!_options.strongMode && node.constKeyword != null) {
|
| - NodeList<TypeName> arguments = typeArguments.arguments;
|
| + NodeList<TypeAnnotation> arguments = typeArguments.arguments;
|
| if (arguments.isNotEmpty) {
|
| _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
|
| CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_LIST);
|
| @@ -948,7 +962,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| Object visitMapLiteral(MapLiteral node) {
|
| TypeArgumentList typeArguments = node.typeArguments;
|
| if (typeArguments != null) {
|
| - NodeList<TypeName> arguments = typeArguments.arguments;
|
| + NodeList<TypeAnnotation> arguments = typeArguments.arguments;
|
| if (!_options.strongMode && arguments.isNotEmpty) {
|
| if (node.constKeyword != null) {
|
| _checkForInvalidTypeArgumentInConstTypedLiteral(arguments,
|
| @@ -974,7 +988,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| if (identifier != null) {
|
| methodName = identifier.name;
|
| }
|
| - TypeName returnTypeName = node.returnType;
|
| + TypeAnnotation returnType = node.returnType;
|
| if (node.isSetter || node.isGetter) {
|
| _checkForMismatchedAccessorTypes(node, methodName);
|
| }
|
| @@ -985,7 +999,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| _checkForInvalidModifierOnBody(
|
| node.body, CompileTimeErrorCode.INVALID_MODIFIER_ON_SETTER);
|
| _checkForWrongNumberOfParametersForSetter(node.name, node.parameters);
|
| - _checkForNonVoidReturnTypeForSetter(returnTypeName);
|
| + _checkForNonVoidReturnTypeForSetter(returnType);
|
| _checkForConflictingStaticSetterAndInstanceMember(node);
|
| } else if (node.isOperator) {
|
| _checkForOptionalParameterInOperator(node);
|
| @@ -994,9 +1008,9 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| }
|
| _checkForConcreteClassWithAbstractMember(node);
|
| _checkForAllInvalidOverrideErrorCodesForMethod(node);
|
| - _checkForTypeAnnotationDeferredClass(returnTypeName);
|
| - _checkForIllegalReturnType(returnTypeName);
|
| - _checkForImplicitDynamicReturn(node.name, node.element);
|
| + _checkForTypeAnnotationDeferredClass(returnType);
|
| + _checkForIllegalReturnType(returnType);
|
| + _checkForImplicitDynamicReturn(node, node.element);
|
| _checkForMustCallSuper(node);
|
| return super.visitMethodDeclaration(node);
|
| } finally {
|
| @@ -1187,9 +1201,9 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
|
|
| @override
|
| Object visitTypeArgumentList(TypeArgumentList node) {
|
| - NodeList<TypeName> list = node.arguments;
|
| - for (TypeName typeName in list) {
|
| - _checkForTypeAnnotationDeferredClass(typeName);
|
| + NodeList<TypeAnnotation> list = node.arguments;
|
| + for (TypeAnnotation type in list) {
|
| + _checkForTypeAnnotationDeferredClass(type);
|
| }
|
| return super.visitTypeArgumentList(node);
|
| }
|
| @@ -3220,15 +3234,16 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| }
|
|
|
| /**
|
| - * Verify that the given [typeName] does not reference any type parameters.
|
| + * Verify that the given [type] does not reference any type parameters.
|
| *
|
| * See [CompileTimeErrorCode.CONST_WITH_TYPE_PARAMETERS].
|
| */
|
| - void _checkForConstWithTypeParameters(TypeName typeName) {
|
| + void _checkForConstWithTypeParameters(TypeAnnotation type) {
|
| // something wrong with AST
|
| - if (typeName == null) {
|
| + if (type is! TypeName) {
|
| return;
|
| }
|
| + TypeName typeName = type;
|
| Identifier name = typeName.name;
|
| if (name == null) {
|
| return;
|
| @@ -3241,7 +3256,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| // check type arguments
|
| TypeArgumentList typeArguments = typeName.typeArguments;
|
| if (typeArguments != null) {
|
| - for (TypeName argument in typeArguments.arguments) {
|
| + for (TypeAnnotation argument in typeArguments.arguments) {
|
| _checkForConstWithTypeParameters(argument);
|
| }
|
| }
|
| @@ -3806,7 +3821,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| * declared return type is assignable to Future, Stream, or Iterable,
|
| * respectively. If not, report the error using [returnType].
|
| */
|
| - void _checkForIllegalReturnType(TypeName returnType) {
|
| + void _checkForIllegalReturnType(TypeAnnotation returnType) {
|
| if (returnType == null) {
|
| // No declared return type, so the return type must be dynamic, which is
|
| // assignable to everything.
|
| @@ -3839,7 +3854,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| * the declared [returnTypeName] is assignable to the required [expectedType]
|
| * and if not report [errorCode].
|
| */
|
| - void _checkForIllegalReturnTypeCode(TypeName returnTypeName,
|
| + void _checkForIllegalReturnTypeCode(TypeAnnotation returnTypeName,
|
| DartType expectedType, StaticTypeWarningCode errorCode) {
|
| DartType returnType = _enclosingFunction.returnType;
|
| if (_options.strongMode) {
|
| @@ -3986,10 +4001,10 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| }
|
| }
|
|
|
| - void _checkForImplicitDynamicType(TypeName node) {
|
| + void _checkForImplicitDynamicType(TypeAnnotation node) {
|
| if (_options.implicitDynamic ||
|
| node == null ||
|
| - node.typeArguments != null) {
|
| + (node is TypeName && node.typeArguments != null)) {
|
| return;
|
| }
|
| DartType type = node.type;
|
| @@ -4457,10 +4472,10 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| * [CompileTimeErrorCode.INVALID_TYPE_ARGUMENT_IN_CONST_MAP].
|
| */
|
| void _checkForInvalidTypeArgumentInConstTypedLiteral(
|
| - NodeList<TypeName> arguments, ErrorCode errorCode) {
|
| - for (TypeName typeName in arguments) {
|
| - if (typeName.type is TypeParameterType) {
|
| - _errorReporter.reportErrorForNode(errorCode, typeName, [typeName.name]);
|
| + NodeList<TypeAnnotation> arguments, ErrorCode errorCode) {
|
| + for (TypeAnnotation type in arguments) {
|
| + if (type is TypeName && type.type is TypeParameterType) {
|
| + _errorReporter.reportErrorForNode(errorCode, type, [type.name]);
|
| }
|
| }
|
| }
|
| @@ -5141,12 +5156,12 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| return;
|
| }
|
| // check return type
|
| - TypeName typeName = declaration.returnType;
|
| - if (typeName != null) {
|
| - DartType type = typeName.type;
|
| + TypeAnnotation annotation = declaration.returnType;
|
| + if (annotation != null) {
|
| + DartType type = annotation.type;
|
| if (type != null && !type.isVoid) {
|
| _errorReporter.reportErrorForNode(
|
| - StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR, typeName);
|
| + StaticWarningCode.NON_VOID_RETURN_FOR_OPERATOR, annotation);
|
| }
|
| }
|
| }
|
| @@ -5157,7 +5172,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| *
|
| * See [StaticWarningCode.NON_VOID_RETURN_FOR_SETTER].
|
| */
|
| - void _checkForNonVoidReturnTypeForSetter(TypeName typeName) {
|
| + void _checkForNonVoidReturnTypeForSetter(TypeAnnotation typeName) {
|
| if (typeName != null) {
|
| DartType type = typeName.type;
|
| if (type != null && !type.isVoid) {
|
| @@ -5579,10 +5594,10 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| *
|
| * See [StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS].
|
| */
|
| - void _checkForTypeAnnotationDeferredClass(TypeName name) {
|
| - if (name != null && name.isDeferred) {
|
| + void _checkForTypeAnnotationDeferredClass(TypeAnnotation type) {
|
| + if (type is TypeName && type.isDeferred) {
|
| _errorReporter.reportErrorForNode(
|
| - StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, name, [name.name]);
|
| + StaticWarningCode.TYPE_ANNOTATION_DEFERRED_CLASS, type, [type.name]);
|
| }
|
| }
|
|
|
| @@ -5592,19 +5607,18 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| *
|
| * See [StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER].
|
| */
|
| - void _checkForTypeAnnotationGenericFunctionParameter(TypeName typeName) {
|
| - if (typeName == null) {
|
| - return;
|
| - }
|
| - Identifier name = typeName.name;
|
| - if (name is SimpleIdentifier) {
|
| - Element element = name.staticElement;
|
| - if (element is TypeParameterElement &&
|
| - element.enclosingElement is ExecutableElement) {
|
| - _errorReporter.reportErrorForNode(
|
| - StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER,
|
| - name,
|
| - [name.name]);
|
| + void _checkForTypeAnnotationGenericFunctionParameter(TypeAnnotation type) {
|
| + if (type is TypeName) {
|
| + Identifier name = type.name;
|
| + if (name is SimpleIdentifier) {
|
| + Element element = name.staticElement;
|
| + if (element is TypeParameterElement &&
|
| + element.enclosingElement is ExecutableElement) {
|
| + _errorReporter.reportErrorForNode(
|
| + StaticWarningCode.TYPE_ANNOTATION_GENERIC_FUNCTION_PARAMETER,
|
| + name,
|
| + [name.name]);
|
| + }
|
| }
|
| }
|
| }
|
| @@ -5631,14 +5645,14 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| List<DartType> parameterTypes = element.type.typeArguments;
|
| List<DartType> arguments = (type as ParameterizedType).typeArguments;
|
| // iterate over each bounded type parameter and corresponding argument
|
| - NodeList<TypeName> typeNameArgList = typeName.typeArguments.arguments;
|
| + NodeList<TypeAnnotation> argumentNodes = typeName.typeArguments.arguments;
|
| int loopThroughIndex =
|
| - math.min(typeNameArgList.length, parameterElements.length);
|
| + math.min(argumentNodes.length, parameterElements.length);
|
| bool shouldSubstitute =
|
| arguments.length != 0 && arguments.length == parameterTypes.length;
|
| for (int i = 0; i < loopThroughIndex; i++) {
|
| - TypeName argTypeName = typeNameArgList[i];
|
| - DartType argType = argTypeName.type;
|
| + TypeAnnotation argumentNode = argumentNodes[i];
|
| + DartType argType = argumentNode.type;
|
| DartType boundType = parameterElements[i].bound;
|
| if (argType != null && boundType != null) {
|
| if (shouldSubstitute) {
|
| @@ -5654,7 +5668,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS;
|
| }
|
| _errorReporter.reportTypeErrorForNode(
|
| - errorCode, argTypeName, [argType, boundType]);
|
| + errorCode, argumentNode, [argType, boundType]);
|
| }
|
| }
|
| }
|
| @@ -5864,12 +5878,11 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| * See [StaticWarningCode.VOID_RETURN_FOR_GETTER].
|
| */
|
| void _checkForVoidReturnType(MethodDeclaration getter) {
|
| - TypeName returnType = getter.returnType;
|
| - if (returnType == null || returnType.name.name != "void") {
|
| - return;
|
| + TypeAnnotation returnType = getter.returnType;
|
| + if (returnType is TypeName && returnType.name.name == "void") {
|
| + _errorReporter.reportErrorForNode(
|
| + StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType);
|
| }
|
| - _errorReporter.reportErrorForNode(
|
| - StaticWarningCode.VOID_RETURN_FOR_GETTER, returnType);
|
| }
|
|
|
| /**
|
| @@ -6077,8 +6090,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| if (element == null || typeArguments == null) {
|
| return;
|
| }
|
| - void reportError(
|
| - TypeName argument, DartType argumentType, DartType parameterType) {
|
| + void reportError(TypeAnnotation argument, DartType argumentType,
|
| + DartType parameterType) {
|
| _errorReporter.reportTypeErrorForNode(
|
| StaticTypeWarningCode.TYPE_ARGUMENT_NOT_MATCHING_BOUNDS,
|
| argument,
|
| @@ -6102,16 +6115,16 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| List<TypeParameterElement> typeParameters,
|
| TypeArgumentList typeArgumentList,
|
| DartType targetType,
|
| - void reportError(
|
| - TypeName argument, DartType argumentType, DartType parameterType)) {
|
| - NodeList<TypeName> typeArguments = typeArgumentList.arguments;
|
| + void reportError(TypeAnnotation argument, DartType argumentType,
|
| + DartType parameterType)) {
|
| + NodeList<TypeAnnotation> typeArguments = typeArgumentList.arguments;
|
| int argumentsLength = typeArguments.length;
|
| int maxIndex = math.min(typeParameters.length, argumentsLength);
|
|
|
| bool shouldSubstitute =
|
| argumentsLength != 0 && argumentsLength == typeParameters.length;
|
| List<DartType> argumentTypes = shouldSubstitute
|
| - ? typeArguments.map((TypeName typeName) => typeName.type).toList()
|
| + ? typeArguments.map((TypeAnnotation type) => type.type).toList()
|
| : null;
|
| List<DartType> parameterTypes = shouldSubstitute
|
| ? typeParameters
|
| @@ -6120,8 +6133,8 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| : null;
|
| List<DartType> targetTypeParameterTypes = null;
|
| for (int i = 0; i < maxIndex; i++) {
|
| - TypeName argTypeName = typeArguments[i];
|
| - DartType argType = argTypeName.type;
|
| + TypeAnnotation argument = typeArguments[i];
|
| + DartType argType = argument.type;
|
| DartType boundType = typeParameters[i].bound;
|
| if (argType != null && boundType != null) {
|
| if (targetType is ParameterizedType) {
|
| @@ -6137,7 +6150,7 @@ class ErrorVerifier extends RecursiveAstVisitor<Object> {
|
| boundType = boundType.substitute2(argumentTypes, parameterTypes);
|
| }
|
| if (!_typeSystem.isSubtypeOf(argType, boundType)) {
|
| - reportError(argTypeName, argType, boundType);
|
| + reportError(argument, argType, boundType);
|
| }
|
| }
|
| }
|
|
|