| Index: pkg/analyzer/lib/src/generated/resolver.dart
|
| diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
|
| index 56f172ace196d22d652526d0c950eea4b3e91570..157c237bdf5412c84b4efb8c686d0c4630de8832 100644
|
| --- a/pkg/analyzer/lib/src/generated/resolver.dart
|
| +++ b/pkg/analyzer/lib/src/generated/resolver.dart
|
| @@ -372,13 +372,13 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
|
| */
|
| bool _checkAllTypeChecks(IsExpression node) {
|
| Expression expression = node.expression;
|
| - TypeName typeName = node.type;
|
| + TypeAnnotation typeName = node.type;
|
| DartType lhsType = expression.staticType;
|
| DartType rhsType = typeName.type;
|
| if (lhsType == null || rhsType == null) {
|
| return false;
|
| }
|
| - String rhsNameStr = typeName.name.name;
|
| + String rhsNameStr = typeName is TypeName ? typeName.name.name : null;
|
| // if x is dynamic
|
| if (rhsType.isDynamic && rhsNameStr == Keyword.DYNAMIC.syntax) {
|
| if (node.notOperator == null) {
|
| @@ -884,7 +884,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
|
| * @return `true` if and only if a hint code is generated on the passed node
|
| * See [HintCode.MISSING_RETURN].
|
| */
|
| - void _checkForMissingReturn(TypeName returnType, FunctionBody body) {
|
| + void _checkForMissingReturn(TypeAnnotation returnType, FunctionBody body) {
|
| // Check that the method or function has a return type, and a function body
|
| if (returnType == null || body == null) {
|
| return;
|
| @@ -1847,8 +1847,7 @@ class Dart2JSVerifier extends RecursiveAstVisitor<Object> {
|
| * [HintCode.IS_NOT_INT].
|
| */
|
| bool _checkForIsDoubleHints(IsExpression node) {
|
| - TypeName typeName = node.type;
|
| - DartType type = typeName.type;
|
| + DartType type = node.type.type;
|
| Element element = type?.element;
|
| if (element != null) {
|
| String typeNameStr = element.name;
|
| @@ -3020,6 +3019,9 @@ class ExitDetector extends GeneralizingAstVisitor<bool> {
|
| }
|
|
|
| @override
|
| + bool visitGenericFunctionType(GenericFunctionType node) => false;
|
| +
|
| + @override
|
| bool visitIdentifier(Identifier node) => false;
|
|
|
| @override
|
| @@ -6092,6 +6094,9 @@ class ResolverVisitor extends ScopedVisitor {
|
| }
|
|
|
| @override
|
| + Object visitGenericFunctionType(GenericFunctionType node) => null;
|
| +
|
| + @override
|
| Object visitHideCombinator(HideCombinator node) => null;
|
|
|
| @override
|
| @@ -8026,7 +8031,7 @@ class ToDoFinder {
|
| }
|
|
|
| /**
|
| - * Helper for resolving [TypeName]s.
|
| + * Helper for resolving types.
|
| *
|
| * The client must set [nameScope] before calling [resolveTypeName].
|
| */
|
| @@ -8305,15 +8310,14 @@ class TypeNameResolver {
|
| return;
|
| }
|
| if (argumentList != null) {
|
| - NodeList<TypeName> arguments = argumentList.arguments;
|
| + NodeList<TypeAnnotation> arguments = argumentList.arguments;
|
| int argumentCount = arguments.length;
|
| List<DartType> parameters = typeSystem.typeFormalsAsTypes(type);
|
| int parameterCount = parameters.length;
|
| List<DartType> typeArguments = new List<DartType>(parameterCount);
|
| if (argumentCount == parameterCount) {
|
| for (int i = 0; i < parameterCount; i++) {
|
| - TypeName argumentTypeName = arguments[i];
|
| - DartType argumentType = _getType(argumentTypeName);
|
| + DartType argumentType = _getType(arguments[i]);
|
| if (argumentType == null) {
|
| argumentType = dynamicType;
|
| }
|
| @@ -8335,16 +8339,12 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * The number of type arguments in the given type name does not match the number of parameters in
|
| - * the corresponding class element. Return the error code that should be used to report this
|
| - * error.
|
| - *
|
| - * @param node the type name with the wrong number of type arguments
|
| - * @return the error code that should be used to report that the wrong number of type arguments
|
| - * were provided
|
| + * The number of type arguments in the given [typeName] does not match the
|
| + * number of parameters in the corresponding class element. Return the error
|
| + * code that should be used to report this error.
|
| */
|
| - ErrorCode _getInvalidTypeParametersErrorCode(TypeName node) {
|
| - AstNode parent = node.parent;
|
| + ErrorCode _getInvalidTypeParametersErrorCode(TypeName typeName) {
|
| + AstNode parent = typeName.parent;
|
| if (parent is ConstructorName) {
|
| parent = parent.parent;
|
| if (parent is InstanceCreationExpression) {
|
| @@ -8359,11 +8359,7 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Checks if the given type name is the target in a redirected constructor.
|
| - *
|
| - * @param typeName the type name to analyze
|
| - * @return some [RedirectingConstructorKind] if the given type name is used as the type in a
|
| - * redirected constructor, or `null` otherwise
|
| + * Checks if the given [typeName] is the target in a redirected constructor.
|
| */
|
| RedirectingConstructorKind _getRedirectingConstructorKind(TypeName typeName) {
|
| AstNode parent = typeName.parent;
|
| @@ -8382,13 +8378,10 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Return the type represented by the given type name.
|
| - *
|
| - * @param typeName the type name representing the type to be returned
|
| - * @return the type represented by the type name
|
| + * Return the type represented by the given type [annotation].
|
| */
|
| - DartType _getType(TypeName typeName) {
|
| - DartType type = typeName.type;
|
| + DartType _getType(TypeAnnotation annotation) {
|
| + DartType type = annotation.type;
|
| if (type == null) {
|
| return undefinedType;
|
| }
|
| @@ -8432,10 +8425,7 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Checks if the given type name is used as the type in an as expression.
|
| - *
|
| - * @param typeName the type name to analyzer
|
| - * @return `true` if the given type name is used as the type in an as expression
|
| + * Checks if the given [typeName] is used as the type in an as expression.
|
| */
|
| bool _isTypeNameInAsExpression(TypeName typeName) {
|
| AstNode parent = typeName.parent;
|
| @@ -8446,10 +8436,8 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Checks if the given type name is used as the exception type in a catch clause.
|
| - *
|
| - * @param typeName the type name to analyzer
|
| - * @return `true` if the given type name is used as the exception type in a catch clause
|
| + * Checks if the given [typeName] is used as the exception type in a catch
|
| + * clause.
|
| */
|
| bool _isTypeNameInCatchClause(TypeName typeName) {
|
| AstNode parent = typeName.parent;
|
| @@ -8460,11 +8448,8 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Checks if the given type name is used as the type in an instance creation expression.
|
| - *
|
| - * @param typeName the type name to analyzer
|
| - * @return `true` if the given type name is used as the type in an instance creation
|
| - * expression
|
| + * Checks if the given [typeName] is used as the type in an instance creation
|
| + * expression.
|
| */
|
| bool _isTypeNameInInstanceCreationExpression(TypeName typeName) {
|
| AstNode parent = typeName.parent;
|
| @@ -8476,10 +8461,7 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Checks if the given type name is used as the type in an is expression.
|
| - *
|
| - * @param typeName the type name to analyzer
|
| - * @return `true` if the given type name is used as the type in an is expression
|
| + * Checks if the given [typeName] is used as the type in an is expression.
|
| */
|
| bool _isTypeNameInIsExpression(TypeName typeName) {
|
| AstNode parent = typeName.parent;
|
| @@ -8490,10 +8472,7 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * Checks if the given type name used in a type argument list.
|
| - *
|
| - * @param typeName the type name to analyzer
|
| - * @return `true` if the given type name is in a type argument list
|
| + * Checks if the given [typeName] used in a type argument list.
|
| */
|
| bool _isTypeNameInTypeArgumentList(TypeName typeName) =>
|
| typeName.parent is TypeArgumentList;
|
| @@ -8516,24 +8495,24 @@ class TypeNameResolver {
|
| }
|
|
|
| /**
|
| - * @return `true` if the name of the given [TypeName] is an built-in identifier.
|
| + * Return `true` if the name of the given [typeName] is an built-in identifier.
|
| */
|
| - static bool _isBuiltInIdentifier(TypeName node) {
|
| - Token token = node.name.beginToken;
|
| + static bool _isBuiltInIdentifier(TypeName typeName) {
|
| + Token token = typeName.name.beginToken;
|
| return token.type == TokenType.KEYWORD;
|
| }
|
|
|
| /**
|
| - * @return `true` if given [TypeName] is used as a type annotation.
|
| + * @return `true` if given [typeName] is used as a type annotation.
|
| */
|
| - static bool _isTypeAnnotation(TypeName node) {
|
| - AstNode parent = node.parent;
|
| + static bool _isTypeAnnotation(TypeName typeName) {
|
| + AstNode parent = typeName.parent;
|
| if (parent is VariableDeclarationList) {
|
| - return identical(parent.type, node);
|
| + return identical(parent.type, typeName);
|
| } else if (parent is FieldFormalParameter) {
|
| - return identical(parent.type, node);
|
| + return identical(parent.type, typeName);
|
| } else if (parent is SimpleFormalParameter) {
|
| - return identical(parent.type, node);
|
| + return identical(parent.type, typeName);
|
| }
|
| return false;
|
| }
|
| @@ -8801,10 +8780,15 @@ class TypeParameterBoundsResolver {
|
| }
|
| }
|
|
|
| - void _resolveTypeName(TypeName typeName) {
|
| - typeName.typeArguments?.arguments?.forEach(_resolveTypeName);
|
| - typeNameResolver.resolveTypeName(typeName);
|
| - // TODO(scheglov) report error when don't apply type bounds for type bounds
|
| + void _resolveTypeName(TypeAnnotation type) {
|
| + if (type is TypeName) {
|
| + type.typeArguments?.arguments?.forEach(_resolveTypeName);
|
| + typeNameResolver.resolveTypeName(type);
|
| + // TODO(scheglov) report error when don't apply type bounds for type bounds
|
| + } else {
|
| + // TODO(brianwilkerson) Add resolution of GenericFunctionType
|
| + throw new ArgumentError('Cannot resolve a ${type.runtimeType}');
|
| + }
|
| }
|
|
|
| void _resolveTypeParameters(
|
| @@ -8812,13 +8796,19 @@ class TypeParameterBoundsResolver {
|
| if (typeParameters != null) {
|
| Scope typeParametersScope = null;
|
| for (TypeParameter typeParameter in typeParameters.typeParameters) {
|
| - TypeName bound = typeParameter.bound;
|
| + TypeAnnotation bound = typeParameter.bound;
|
| if (bound != null) {
|
| Element typeParameterElement = typeParameter.name.staticElement;
|
| if (typeParameterElement is TypeParameterElementImpl) {
|
| if (LibraryElementImpl.hasResolutionCapability(
|
| library, LibraryResolutionCapability.resolvedTypeNames)) {
|
| - bound.type = typeParameterElement.bound;
|
| + if (bound is TypeName) {
|
| + bound.type = typeParameterElement.bound;
|
| + } else {
|
| + // TODO(brianwilkerson) Add resolution of GenericFunctionType
|
| + throw new ArgumentError(
|
| + 'Cannot resolve a ${bound.runtimeType}');
|
| + }
|
| } else {
|
| libraryScope ??= new LibraryScope(library);
|
| typeParametersScope ??= createTypeParametersScope();
|
| @@ -9492,7 +9482,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| TypeSystem _typeSystem;
|
|
|
| /**
|
| - * The helper to resolve [TypeName]s.
|
| + * The helper to resolve types.
|
| */
|
| TypeNameResolver _typeNameResolver;
|
|
|
| @@ -9574,7 +9564,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| // If an 'on' clause is provided the type of the exception parameter is
|
| // the type in the 'on' clause. Otherwise, the type of the exception
|
| // parameter is 'Object'.
|
| - TypeName exceptionTypeName = node.exceptionType;
|
| + TypeAnnotation exceptionTypeName = node.exceptionType;
|
| DartType exceptionType;
|
| if (exceptionTypeName == null) {
|
| exceptionType = typeProvider.dynamicType;
|
| @@ -9713,7 +9703,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| Object visitDeclaredIdentifier(DeclaredIdentifier node) {
|
| super.visitDeclaredIdentifier(node);
|
| DartType declaredType;
|
| - TypeName typeName = node.type;
|
| + TypeAnnotation typeName = node.type;
|
| if (typeName == null) {
|
| declaredType = _dynamicType;
|
| } else {
|
| @@ -9732,7 +9722,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| FormalParameterList parameterList = node.parameters;
|
| if (parameterList == null) {
|
| DartType type;
|
| - TypeName typeName = node.type;
|
| + TypeAnnotation typeName = node.type;
|
| if (typeName == null) {
|
| element.hasImplicitType = true;
|
| if (element is FieldFormalParameterElement) {
|
| @@ -9955,7 +9945,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| Object visitSimpleFormalParameter(SimpleFormalParameter node) {
|
| super.visitSimpleFormalParameter(node);
|
| DartType declaredType;
|
| - TypeName typeName = node.type;
|
| + TypeAnnotation typeName = node.type;
|
| if (typeName == null) {
|
| declaredType = _dynamicType;
|
| } else {
|
| @@ -9994,7 +9984,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| // Bounds of parameters of classes and function type aliases are
|
| // already resolved.
|
| } else {
|
| - TypeName bound = node.bound;
|
| + TypeAnnotation bound = node.bound;
|
| if (bound != null) {
|
| TypeParameterElementImpl typeParameter =
|
| node.name.staticElement as TypeParameterElementImpl;
|
| @@ -10019,7 +10009,7 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| }
|
| // Resolve the type.
|
| DartType declaredType;
|
| - TypeName typeName = variableList.type;
|
| + TypeAnnotation typeName = variableList.type;
|
| if (typeName == null) {
|
| declaredType = _dynamicType;
|
| } else {
|
| @@ -10033,13 +10023,10 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| }
|
|
|
| /**
|
| - * Given a type name representing the return type of a function, compute the return type of the
|
| + * Given the [returnType] of a function, compute the return type of the
|
| * function.
|
| - *
|
| - * @param returnType the type name representing the return type of the function
|
| - * @return the return type that was computed
|
| */
|
| - DartType _computeReturnType(TypeName returnType) {
|
| + DartType _computeReturnType(TypeAnnotation returnType) {
|
| if (returnType == null) {
|
| return _dynamicType;
|
| } else {
|
| @@ -10121,13 +10108,8 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| }
|
|
|
| /**
|
| - * Resolve the types in the given with and implements clauses and associate those types with the
|
| - * given class element.
|
| - *
|
| - * @param classElement the class element with which the mixin and interface types are to be
|
| - * associated
|
| - * @param withClause the with clause to be resolved
|
| - * @param implementsClause the implements clause to be resolved
|
| + * Resolve the types in the given [withClause] and [implementsClause] and
|
| + * associate those types with the given [classElement].
|
| */
|
| void _resolve(ClassElementImpl classElement, WithClause withClause,
|
| ImplementsClause implementsClause) {
|
| @@ -10236,15 +10218,12 @@ class TypeResolverVisitor extends ScopedVisitor {
|
| }
|
|
|
| /**
|
| - * Given a parameter element, create a function type based on the given return type and parameter
|
| - * list and associate the created type with the element.
|
| - *
|
| - * @param element the parameter element whose type is to be set
|
| - * @param returnType the (possibly `null`) return type of the function
|
| - * @param parameterList the list of parameters to the function
|
| + * Given a parameter [element], create a function type based on the given
|
| + * [returnType] and [parameterList] and associate the created type with the
|
| + * element.
|
| */
|
| void _setFunctionTypedParameterType(ParameterElementImpl element,
|
| - TypeName returnType, FormalParameterList parameterList) {
|
| + TypeAnnotation returnType, FormalParameterList parameterList) {
|
| List<ParameterElement> parameters = _getElements(parameterList);
|
| FunctionElementImpl functionElement = new FunctionElementImpl.forNode(null);
|
| functionElement.isSynthetic = true;
|
|
|