From eba7e490316c0199f12663828938e94881a7d123 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Tue, 21 Jan 2025 12:54:19 -0800 Subject: [PATCH] [analyzer] Change VariableElementImpl.type setter to TypeImpl. The types of `LocalVariableElementImpl2.type=`, `PropertyInducingElementImpl.type=`, and `VariableElementImpl.type=` are all changed to accept `TypeImpl` rather than `DartType`. To reduce the number of casts that need to be added, some field types, getter types, method return types, and method parameter types are changed to `Impl` types in the following classes: - `DeclarationBuilder` - `ElementFactory` - `ElementsTypesMixin` - `ForResolver` - `FunctionExpressionResolver` - `FunctionTypeBuilder` - `FunctionTypeTest` - `InstanceMemberInferrer` - `LocalVariableElementImpl2` - `NamedTypeBuilder` - `NonCovariantTypeParameterPositionVisitorTest` - `ReplacementVisitor` - `ResolutionReader` - `ResolutionVisitor` - `TypeBuilder` - `TypeReferencesAnyTest` - `TypesBuilder` - `_MockSdkElementsBuilder` - `_Node` There is no change to the analyzer public API. This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API. See https://github.com/dart-lang/sdk/issues/59763. Change-Id: I726bb1ce414eec3f360ae655c1f55e6be9e713fe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405242 Reviewed-by: Konstantin Shcheglov Commit-Queue: Paul Berry --- .../lib/src/dart/element/element.dart | 16 ++--- .../src/dart/element/replacement_visitor.dart | 8 ++- .../lib/src/dart/element/type_algebra.dart | 4 +- .../lib/src/dart/resolver/for_resolver.dart | 2 +- .../function_expression_resolver.dart | 15 +++-- .../src/dart/resolver/resolution_visitor.dart | 7 ++- .../generated/testing/element_factory.dart | 20 +++--- .../lib/src/summary2/bundle_reader.dart | 2 +- .../lib/src/summary2/extension_type.dart | 2 +- .../src/summary2/function_type_builder.dart | 8 +-- .../summary2/instance_member_inferrer.dart | 26 +++++--- .../lib/src/summary2/macro_declarations.dart | 15 +++-- .../lib/src/summary2/named_type_builder.dart | 2 +- .../lib/src/summary2/type_builder.dart | 2 +- .../lib/src/summary2/types_builder.dart | 14 ++--- .../src/test_utilities/mock_sdk_elements.dart | 62 +++++++++---------- .../test/generated/elements_types_mixin.dart | 10 +-- .../test/src/dart/element/element_test.dart | 6 +- .../src/dart/element/function_type_test.dart | 2 +- .../element/least_greatest_closure_test.dart | 3 +- ...ovariant_type_parameter_position_test.dart | 3 +- .../dart/element/replace_top_bottom_test.dart | 3 +- .../element/runtime_type_equality_test.dart | 5 +- .../element/type_references_any_test.dart | 2 +- .../dart/element/upper_lower_bound_test.dart | 27 ++++---- 25 files changed, 148 insertions(+), 118 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index edc8c24246f0..141d88ae4c7d 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -7844,9 +7844,9 @@ class LocalVariableElementImpl2 extends PromotableElementImpl2 Metadata get metadata2 => wrappedElement.metadata2; @override - DartType get type => _wrappedElement.type; + TypeImpl get type => _wrappedElement.type; - set type(DartType type) => _wrappedElement.type = type; + set type(TypeImpl type) => _wrappedElement.type = type; LocalVariableElementImpl get wrappedElement { return _wrappedElement; @@ -9310,7 +9310,9 @@ class ParameterElementImpl extends VariableElementImpl nameOffset: -1, parameterKind: parameterKind, ); - element.type = type; + // TODO(paulberry): remove this cast by changing the type of the `type` + // parameter. + element.type = type as TypeImpl; element.isSynthetic = true; return element; } @@ -10357,7 +10359,7 @@ abstract class PropertyInducingElementImpl } @override - set type(DartType type) { + set type(TypeImpl type) { super.type = type; // Reset cached types of synthetic getters and setters. // TODO(scheglov): Consider not caching these types. @@ -11630,10 +11632,8 @@ abstract class VariableElementImpl extends ElementImpl @override TypeImpl get type => _type!; - set type(DartType type) { - // TODO(paulberry): eliminate this cast by changing the setter parameter - // type to `TypeImpl`. - _type = type as TypeImpl; + set type(TypeImpl type) { + _type = type; } @override diff --git a/pkg/analyzer/lib/src/dart/element/replacement_visitor.dart b/pkg/analyzer/lib/src/dart/element/replacement_visitor.dart index 7d3d4d8c8333..30b102d302ba 100644 --- a/pkg/analyzer/lib/src/dart/element/replacement_visitor.dart +++ b/pkg/analyzer/lib/src/dart/element/replacement_visitor.dart @@ -58,7 +58,7 @@ class ReplacementVisitor required FunctionTypeBuilder type, required List? newTypeParameters, required List? newParameters, - required DartType? newReturnType, + required TypeImpl? newReturnType, required NullabilitySuffix? newNullability, }) { if (newNullability == null && @@ -311,13 +311,15 @@ class ReplacementVisitor } } - DartType? visitType(DartType? type) { + TypeImpl? visitType(DartType? type) { if (type == null) return null; var result = type.accept(this); if (substitution != null) { result = substitution.substituteType(result ?? type); } - return result; + // TODO(paulberry): eliminate this cast by changing `ReplacementVisitor` + // to implement `TypeVisitor`. + return result as TypeImpl?; } var newReturnType = visitType(node.returnType); diff --git a/pkg/analyzer/lib/src/dart/element/type_algebra.dart b/pkg/analyzer/lib/src/dart/element/type_algebra.dart index 2fecad374901..33dc90d9bc07 100644 --- a/pkg/analyzer/lib/src/dart/element/type_algebra.dart +++ b/pkg/analyzer/lib/src/dart/element/type_algebra.dart @@ -554,7 +554,9 @@ abstract class _TypeSubstitutor inner.invertVariance(); - var returnType = type.returnType.accept(inner); + // TODO(paulberry): eliminate this cast by changing `_TypeSubstitutor` to + // implement `TypeVisitor`. + var returnType = type.returnType.accept(inner) as TypeImpl; if (useCounter == before) return type; diff --git a/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart index aa02df4f1dab..20c7fa737a10 100644 --- a/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/for_resolver.dart @@ -99,7 +99,7 @@ class ForResolver { /// a type for the elements being iterated over. Inference is based /// on the type of the iterator or stream over which the foreach loop /// is defined. - DartType _computeForEachElementType(Expression iterable, bool isAsync) { + TypeImpl _computeForEachElementType(ExpressionImpl iterable, bool isAsync) { var iterableType = iterable.staticType; if (iterableType == null) { return InvalidTypeImpl.instance; diff --git a/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart index 05f942b8fbd0..18b7fef1600f 100644 --- a/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart +++ b/pkg/analyzer/lib/src/dart/resolver/function_expression_resolver.dart @@ -80,7 +80,7 @@ class FunctionExpressionResolver { return; } - void inferType(ParameterElementImpl p, DartType inferredType) { + void inferType(ParameterElementImpl p, TypeImpl inferredType) { // Check that there is no declared type, and that we have not already // inferred a type in some fashion. if (p.hasImplicitType && p.type is DynamicType) { @@ -108,8 +108,11 @@ class FunctionExpressionResolver { Iterator fnPositional = contextType.parameters.where((p) => p.isPositional).iterator; while (positional.moveNext() && fnPositional.moveNext()) { - inferType(positional.current as ParameterElementImpl, - fnPositional.current.type); + inferType( + positional.current as ParameterElementImpl, + // TODO(paulberry): eliminate this cast by changing the type of + // `contextType` to `FunctionTypeImpl`. + fnPositional.current.type as TypeImpl); } } @@ -121,7 +124,11 @@ class FunctionExpressionResolver { if (!namedParameterTypes.containsKey(p.name)) { continue; } - inferType(p as ParameterElementImpl, namedParameterTypes[p.name]!); + inferType( + p as ParameterElementImpl, + // TODO(paulberry): eliminate this cast by changing the type of + // `contextType` to `FunctionTypeImpl`. + namedParameterTypes[p.name]! as TypeImpl); } } } diff --git a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart index ede4d5179883..94005939f5dc 100644 --- a/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart +++ b/pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart @@ -23,6 +23,7 @@ import 'package:analyzer/src/dart/element/element.dart'; import 'package:analyzer/src/dart/element/scope.dart'; import 'package:analyzer/src/dart/element/type.dart'; import 'package:analyzer/src/dart/element/type_constraint_gatherer.dart'; +import 'package:analyzer/src/dart/element/type_provider.dart'; import 'package:analyzer/src/dart/resolver/ast_rewrite.dart'; import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart'; import 'package:analyzer/src/dart/resolver/named_type_resolver.dart'; @@ -73,7 +74,7 @@ class ElementHolder { /// 5. Rewrite AST where resolution provides a more accurate understanding. class ResolutionVisitor extends RecursiveAstVisitor { final LibraryElementImpl _libraryElement; - final TypeProvider _typeProvider; + final TypeProviderImpl _typeProvider; final CompilationUnitElementImpl _unitElement; final ErrorReporter _errorReporter; final AstRewriter _astRewriter; @@ -177,7 +178,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { this.dataForTesting, ); - DartType get _dynamicType => _typeProvider.dynamicType; + TypeImpl get _dynamicType => _typeProvider.dynamicType; @override void visitAnnotation(covariant AnnotationImpl node) { @@ -1402,7 +1403,7 @@ class ResolutionVisitor extends RecursiveAstVisitor { var localElement = node.declaredElement as LocalVariableElementImpl; element = localElement; - var varList = node.parent as VariableDeclarationList; + var varList = node.parent as VariableDeclarationListImpl; localElement.hasImplicitType = varList.type == null; localElement.hasInitializer = initializerNode != null; localElement.type = varList.type?.type ?? _dynamicType; diff --git a/pkg/analyzer/lib/src/generated/testing/element_factory.dart b/pkg/analyzer/lib/src/generated/testing/element_factory.dart index 6c7aa909ff13..baaf8a34e01a 100644 --- a/pkg/analyzer/lib/src/generated/testing/element_factory.dart +++ b/pkg/analyzer/lib/src/generated/testing/element_factory.dart @@ -120,7 +120,7 @@ class ElementFactory { static ConstructorElementImpl constructorElement( ClassElement definingClass, String? name, bool isConst, - [List argumentTypes = const []]) { + [List argumentTypes = const []]) { var offset = name == null ? -1 : 0; // A constructor declared as `C.new` is unnamed, and is modeled as such. var constructor = name == null || name == 'new' @@ -146,11 +146,11 @@ class ElementFactory { static ConstructorElementImpl constructorElement2( ClassElement definingClass, String? name, - [List argumentTypes = const []]) => + [List argumentTypes = const []]) => constructorElement(definingClass, name, false, argumentTypes); static FieldElementImpl fieldElement( - String name, bool isStatic, bool isFinal, bool isConst, DartType type, + String name, bool isStatic, bool isFinal, bool isConst, TypeImpl type, {ExpressionImpl? initializer}) { FieldElementImpl field = isConst ? ConstFieldElementImpl(name, 0) : FieldElementImpl(name, 0); @@ -184,7 +184,7 @@ class ElementFactory { } static PropertyAccessorElementImpl getterElement( - String name, bool isStatic, DartType type) { + String name, bool isStatic, TypeImpl type) { FieldElementImpl field = FieldElementImpl(name, -1); field.isStatic = isStatic; field.isSynthetic = true; @@ -227,7 +227,7 @@ class ElementFactory { LocalVariableElementImpl(name, 0); static MethodElementImpl methodElement(String methodName, DartType returnType, - [List argumentTypes = const []]) { + [List argumentTypes = const []]) { MethodElementImpl method = MethodElementImpl(methodName, 0); method.parameters = _requiredParameters(argumentTypes); method.returnType = returnType; @@ -276,7 +276,7 @@ class ElementFactory { ); } - static ParameterElementImpl namedParameter2(String name, DartType type) { + static ParameterElementImpl namedParameter2(String name, TypeImpl type) { var parameter = ParameterElementImpl( name: name, nameOffset: 0, @@ -294,7 +294,7 @@ class ElementFactory { ); } - static ParameterElementImpl positionalParameter2(String name, DartType type) { + static ParameterElementImpl positionalParameter2(String name, TypeImpl type) { var parameter = ParameterElementImpl( name: name, nameOffset: 0, @@ -314,7 +314,7 @@ class ElementFactory { ); } - static ParameterElementImpl requiredParameter2(String name, DartType type) { + static ParameterElementImpl requiredParameter2(String name, TypeImpl type) { var parameter = ParameterElementImpl( name: name, nameOffset: 0, @@ -325,7 +325,7 @@ class ElementFactory { } static PropertyAccessorElementImpl setterElement( - String name, bool isStatic, DartType type) { + String name, bool isStatic, TypeImpl type) { FieldElementImpl field = FieldElementImpl(name, -1); field.isStatic = isStatic; field.isSynthetic = true; @@ -367,7 +367,7 @@ class ElementFactory { } static List _requiredParameters( - List argumentTypes) { + List argumentTypes) { var parameters = argumentTypes.mapIndexed((index, type) { var parameter = ParameterElementImpl( name: 'a$index', diff --git a/pkg/analyzer/lib/src/summary2/bundle_reader.dart b/pkg/analyzer/lib/src/summary2/bundle_reader.dart index b08a3d0e2222..3f630a0a1616 100644 --- a/pkg/analyzer/lib/src/summary2/bundle_reader.dart +++ b/pkg/analyzer/lib/src/summary2/bundle_reader.dart @@ -2170,7 +2170,7 @@ class ResolutionReader { } } - DartType readRequiredType() { + TypeImpl readRequiredType() { return readType()!; } diff --git a/pkg/analyzer/lib/src/summary2/extension_type.dart b/pkg/analyzer/lib/src/summary2/extension_type.dart index 0721f5eb4b24..1e16b828bdd7 100644 --- a/pkg/analyzer/lib/src/summary2/extension_type.dart +++ b/pkg/analyzer/lib/src/summary2/extension_type.dart @@ -151,7 +151,7 @@ class _Node extends graph.Node<_Node> { _evaluateWithType(type); } - void _evaluateWithType(DartType type) { + void _evaluateWithType(TypeImpl type) { var typeSystem = element.library.typeSystem; element.representation.type = type; diff --git a/pkg/analyzer/lib/src/summary2/function_type_builder.dart b/pkg/analyzer/lib/src/summary2/function_type_builder.dart index 5aa072cc654a..91888f5cdc2a 100644 --- a/pkg/analyzer/lib/src/summary2/function_type_builder.dart +++ b/pkg/analyzer/lib/src/summary2/function_type_builder.dart @@ -23,7 +23,7 @@ class FunctionTypeBuilder extends TypeBuilder { final List typeFormals; final List parameters; - final DartType returnType; + final TypeImpl returnType; @override final NullabilitySuffix nullabilitySuffix; @@ -71,7 +71,7 @@ class FunctionTypeBuilder extends TypeBuilder { } @override - DartType build() { + TypeImpl build() { var type = _type; if (type != null) { return type; @@ -153,7 +153,7 @@ class FunctionTypeBuilder extends TypeBuilder { } /// If the [type] is a [TypeBuilder], build it; otherwise return as is. - static DartType _buildType(DartType type) { + static TypeImpl _buildType(TypeImpl type) { if (type is TypeBuilder) { return type.build(); } else { @@ -162,7 +162,7 @@ class FunctionTypeBuilder extends TypeBuilder { } /// Return the type of the [node] as is, possibly a [TypeBuilder]. - static DartType _getNodeType(TypeAnnotation? node) { + static TypeImpl _getNodeType(TypeAnnotation? node) { if (node == null) { return _dynamicType; } else { diff --git a/pkg/analyzer/lib/src/summary2/instance_member_inferrer.dart b/pkg/analyzer/lib/src/summary2/instance_member_inferrer.dart index 9497b42be254..c25db8742473 100644 --- a/pkg/analyzer/lib/src/summary2/instance_member_inferrer.dart +++ b/pkg/analyzer/lib/src/summary2/instance_member_inferrer.dart @@ -127,7 +127,7 @@ class InstanceMemberInferrer { ); overriddenSetters ??= const []; - DartType combinedGetterType() { + TypeImpl combinedGetterType() { var combinedGetter = inheritance.combineSignatures( targetClass: currentInterfaceElement, candidates: overriddenGetters!, @@ -135,12 +135,14 @@ class InstanceMemberInferrer { name: getterName, ); if (combinedGetter != null) { - return combinedGetter.returnType; + // TODO(paulberry): eliminate this cast by changing the return type of + // `InheritanceManager3.combineSignatures`. + return combinedGetter.returnType as TypeImpl; } return DynamicTypeImpl.instance; } - DartType combinedSetterType() { + TypeImpl combinedSetterType() { var combinedSetter = inheritance.combineSignatures( targetClass: currentInterfaceElement, candidates: overriddenSetters!, @@ -150,7 +152,9 @@ class InstanceMemberInferrer { if (combinedSetter != null) { var parameters = combinedSetter.parameters; if (parameters.isNotEmpty) { - return parameters[0].type; + // TODO(paulberry): eliminate this cast by changing the return type of + // `InheritanceManager3.combineSignatures`. + return parameters[0].type as TypeImpl; } } return DynamicTypeImpl.instance; @@ -373,12 +377,16 @@ class InstanceMemberInferrer { if (parameter is FieldFormalParameterElementImpl) { var field = parameter.field; if (field != null) { - parameter.type = field.type; + // TODO(paulberry): eliminate this cast by changing the type of + // `FieldFormalParameterElementImpl.field`. + parameter.type = field.type as TypeImpl; } } else if (parameter is SuperFormalParameterElementImpl) { var superParameter = parameter.superConstructorParameter; if (superParameter != null) { - parameter.type = superParameter.type; + // TODO(paulberry): eliminate this cast by changing the type of + // `SuperFormalParameterElementImpl.superConstructorParameter`. + parameter.type = superParameter.type as TypeImpl; } else { parameter.type = DynamicTypeImpl.instance; } @@ -544,7 +552,9 @@ class InstanceMemberInferrer { combinedSignatureType.parameters, ); if (matchingParameter != null) { - parameter.type = matchingParameter.type; + // TODO(paulberry): eliminate this cast by changing the return type of + // `_getCorrespondingParameter`. + parameter.type = matchingParameter.type as TypeImpl; } else { parameter.type = DynamicTypeImpl.instance; } @@ -724,7 +734,7 @@ class InstanceMemberInferrer { return false; } - static void _setFieldType(FieldElementImpl field, DartType type) { + static void _setFieldType(FieldElementImpl field, TypeImpl type) { field.type = type; } } diff --git a/pkg/analyzer/lib/src/summary2/macro_declarations.dart b/pkg/analyzer/lib/src/summary2/macro_declarations.dart index 9010af8dd269..427d4c158bc4 100644 --- a/pkg/analyzer/lib/src/summary2/macro_declarations.dart +++ b/pkg/analyzer/lib/src/summary2/macro_declarations.dart @@ -349,11 +349,10 @@ class DeclarationBuilder { } } - DartType resolveType(macro.TypeAnnotationCode typeCode) { + TypeImpl resolveType(macro.TypeAnnotationCode typeCode) { switch (typeCode) { case macro.NullableTypeAnnotationCode(): var type = resolveType(typeCode.underlyingType); - type as TypeImpl; return type.withNullability(NullabilitySuffix.question); case macro.FunctionTypeAnnotationCode(): return _resolveTypeCodeFunction(typeCode); @@ -546,7 +545,7 @@ class DeclarationBuilder { ); } - DartType _resolveTypeCodeNamed(macro.NamedTypeAnnotationCode typeCode) { + TypeImpl _resolveTypeCodeNamed(macro.NamedTypeAnnotationCode typeCode) { var identifier = typeCode.name as IdentifierImpl; if (identifier is IdentifierImplVoid) { return VoidTypeImpl.instance; @@ -576,15 +575,19 @@ class DeclarationBuilder { } } - DartType _resolveTypeCodeOmitted(macro.OmittedTypeAnnotationCode typeCode) { + TypeImpl _resolveTypeCodeOmitted(macro.OmittedTypeAnnotationCode typeCode) { var omittedType = typeCode.typeAnnotation; switch (omittedType) { case OmittedTypeAnnotationDynamic(): return DynamicTypeImpl.instance; case OmittedTypeAnnotationFunctionReturnType(): - return omittedType.element.returnType; + // TODO(paulberry): eliminate this cast by changing the type of + // `macro.OmittedTypeAnnotationCode.typeAnnotation`. + return omittedType.element.returnType as TypeImpl; case OmittedTypeAnnotationVariable(): - return omittedType.element.type; + // TODO(paulberry): eliminate this cast by changing the type of + // `macro.OmittedTypeAnnotationCode.typeAnnotation`. + return omittedType.element.type as TypeImpl; default: throw UnimplementedError('${omittedType.runtimeType}'); } diff --git a/pkg/analyzer/lib/src/summary2/named_type_builder.dart b/pkg/analyzer/lib/src/summary2/named_type_builder.dart index 6110ccff3fb7..c1724c6ff99f 100644 --- a/pkg/analyzer/lib/src/summary2/named_type_builder.dart +++ b/pkg/analyzer/lib/src/summary2/named_type_builder.dart @@ -90,7 +90,7 @@ class NamedTypeBuilder extends TypeBuilder { } @override - DartType build() { + TypeImpl build() { if (_type != null) { return _type!; } diff --git a/pkg/analyzer/lib/src/summary2/type_builder.dart b/pkg/analyzer/lib/src/summary2/type_builder.dart index b9a0b930371d..5d69716865ee 100644 --- a/pkg/analyzer/lib/src/summary2/type_builder.dart +++ b/pkg/analyzer/lib/src/summary2/type_builder.dart @@ -11,7 +11,7 @@ abstract class TypeBuilder implements TypeImpl { /// Does nothing if the type has been already built. /// /// Return the built type. - DartType build(); + TypeImpl build(); @override dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); diff --git a/pkg/analyzer/lib/src/summary2/types_builder.dart b/pkg/analyzer/lib/src/summary2/types_builder.dart index b0cf03e20405..b233c4c2fb2e 100644 --- a/pkg/analyzer/lib/src/summary2/types_builder.dart +++ b/pkg/analyzer/lib/src/summary2/types_builder.dart @@ -97,7 +97,7 @@ class TypesBuilder { _MixinsInference(_toInferMixins).perform(); } - FunctionType _buildFunctionType( + FunctionTypeImpl _buildFunctionType( TypeParameterList? typeParameterList, TypeAnnotation? returnTypeNode, FormalParameterList parameterList, @@ -167,7 +167,7 @@ class TypesBuilder { _extensionDeclaration(node); } else if (node is ExtensionTypeDeclarationImpl) { _extensionTypeDeclaration(node); - } else if (node is FieldFormalParameter) { + } else if (node is FieldFormalParameterImpl) { _fieldFormalParameter(node); } else if (node is FunctionDeclaration) { var returnType = node.returnType?.type; @@ -203,14 +203,14 @@ class TypesBuilder { element.returnType = returnType; } else if (node is MixinDeclaration) { _mixinDeclaration(node); - } else if (node is SimpleFormalParameter) { + } else if (node is SimpleFormalParameterImpl) { var element = node.declaredElement as ParameterElementImpl; element.type = node.type?.type ?? _dynamicType; - } else if (node is SuperFormalParameter) { + } else if (node is SuperFormalParameterImpl) { _superFormalParameter(node); } else if (node is TypeParameterImpl) { _typeParameter(node); - } else if (node is VariableDeclarationList) { + } else if (node is VariableDeclarationListImpl) { var type = node.type?.type; if (type != null) { for (var variable in node.variables) { @@ -260,7 +260,7 @@ class TypesBuilder { _updatedAugmented(element); } - void _fieldFormalParameter(FieldFormalParameter node) { + void _fieldFormalParameter(FieldFormalParameterImpl node) { var element = node.declaredElement as FieldFormalParameterElementImpl; var parameterList = node.parameters; if (parameterList != null) { @@ -342,7 +342,7 @@ class TypesBuilder { } } - void _superFormalParameter(SuperFormalParameter node) { + void _superFormalParameter(SuperFormalParameterImpl node) { var element = node.declaredElement as SuperFormalParameterElementImpl; var parameterList = node.parameters; if (parameterList != null) { diff --git a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart index 20e089346ed3..6d04c6e65cb2 100644 --- a/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart +++ b/pkg/analyzer/lib/src/test_utilities/mock_sdk_elements.dart @@ -67,13 +67,13 @@ class _MockSdkElementsBuilder { ClassElementImpl? _symbolElement; ClassElementImpl? _typeElement; - InterfaceType? _boolType; - InterfaceType? _doubleType; - InterfaceType? _intType; - InterfaceType? _numType; - InterfaceType? _objectType; - InterfaceType? _stringType; - InterfaceType? _typeType; + InterfaceTypeImpl? _boolType; + InterfaceTypeImpl? _doubleType; + InterfaceTypeImpl? _intType; + InterfaceTypeImpl? _numType; + InterfaceTypeImpl? _objectType; + InterfaceTypeImpl? _stringType; + InterfaceTypeImpl? _typeType; late LibraryElementImpl _asyncLibrary; late CompilationUnitElementImpl _asyncUnit; @@ -109,7 +109,7 @@ class _MockSdkElementsBuilder { return boolElement; } - InterfaceType get boolType { + InterfaceTypeImpl get boolType { return _boolType ??= _interfaceType(boolElement); } @@ -238,7 +238,7 @@ class _MockSdkElementsBuilder { return doubleElement; } - InterfaceType get doubleType { + InterfaceTypeImpl get doubleType { return _doubleType ??= _interfaceType(doubleElement); } @@ -259,7 +259,7 @@ class _MockSdkElementsBuilder { return functionElement; } - InterfaceType get functionType { + InterfaceTypeImpl get functionType { return _interfaceType(functionElement); } @@ -380,7 +380,7 @@ class _MockSdkElementsBuilder { return intElement; } - InterfaceType get intType { + InterfaceTypeImpl get intType { return _intType ??= _interfaceType(intElement); } @@ -615,7 +615,7 @@ class _MockSdkElementsBuilder { return numElement; } - InterfaceType get numType { + InterfaceTypeImpl get numType { return _numType ??= _interfaceType(numElement); } @@ -651,7 +651,7 @@ class _MockSdkElementsBuilder { return objectElement; } - InterfaceType get objectType { + InterfaceTypeImpl get objectType { return _objectType ??= _interfaceType(objectElement); } @@ -686,7 +686,7 @@ class _MockSdkElementsBuilder { return recordElement; } - InterfaceType get recordType { + InterfaceTypeImpl get recordType { return _interfaceType(recordElement); } @@ -831,7 +831,7 @@ class _MockSdkElementsBuilder { return stringElement; } - InterfaceType get stringType { + InterfaceTypeImpl get stringType { return _stringType ??= _interfaceType(stringElement); } @@ -875,48 +875,48 @@ class _MockSdkElementsBuilder { return typeElement; } - InterfaceType get typeType { + InterfaceTypeImpl get typeType { return _typeType ??= _interfaceType(typeElement); } VoidTypeImpl get voidType => VoidTypeImpl.instance; - InterfaceType futureOrType(DartType elementType) { + InterfaceTypeImpl futureOrType(DartType elementType) { return _interfaceType( futureOrElement, typeArguments: [elementType], ); } - InterfaceType futureType(DartType elementType) { + InterfaceTypeImpl futureType(DartType elementType) { return _interfaceType( futureElement, typeArguments: [elementType], ); } - InterfaceType iterableType(DartType elementType) { + InterfaceTypeImpl iterableType(DartType elementType) { return _interfaceType( iterableElement, typeArguments: [elementType], ); } - InterfaceType iteratorType(DartType elementType) { + InterfaceTypeImpl iteratorType(DartType elementType) { return _interfaceType( iteratorElement, typeArguments: [elementType], ); } - InterfaceType listType(DartType elementType) { + InterfaceTypeImpl listType(DartType elementType) { return _interfaceType( listElement, typeArguments: [elementType], ); } - InterfaceType streamSubscriptionType(DartType valueType) { + InterfaceTypeImpl streamSubscriptionType(DartType valueType) { return _interfaceType( streamSubscriptionElement, typeArguments: [valueType], @@ -1007,7 +1007,7 @@ class _MockSdkElementsBuilder { FieldElementImpl _field( String name, - DartType type, { + TypeImpl type, { bool isConst = false, bool isFinal = false, bool isStatic = false, @@ -1029,7 +1029,7 @@ class _MockSdkElementsBuilder { return fragment; } - FunctionType _functionType({ + FunctionTypeImpl _functionType({ required DartType returnType, List typeFormals = const [], List parameters = const [], @@ -1044,7 +1044,7 @@ class _MockSdkElementsBuilder { PropertyAccessorElementImpl _getter( String name, - DartType type, { + TypeImpl type, { bool isStatic = false, }) { var field = FieldElementImpl(name, -1); @@ -1063,7 +1063,7 @@ class _MockSdkElementsBuilder { return getter; } - InterfaceType _interfaceType( + InterfaceTypeImpl _interfaceType( InterfaceElementImpl element, { List typeArguments = const [], }) { @@ -1086,7 +1086,7 @@ class _MockSdkElementsBuilder { ..typeParameters = typeFormals; } - ParameterElementImpl _namedParameter(String name, DartType type, + ParameterElementImpl _namedParameter(String name, TypeImpl type, {String? initializerCode}) { var parameter = DefaultParameterElementImpl( name: name, @@ -1167,7 +1167,7 @@ class _MockSdkElementsBuilder { _fillLibraryFromFragment(_coreLibrary, _coreUnit); } - ParameterElementImpl _positionalParameter(String name, DartType type) { + ParameterElementImpl _positionalParameter(String name, TypeImpl type) { var parameter = ParameterElementImpl( name: name, nameOffset: 0, @@ -1177,7 +1177,7 @@ class _MockSdkElementsBuilder { return parameter; } - ParameterElementImpl _requiredParameter(String name, DartType type) { + ParameterElementImpl _requiredParameter(String name, TypeImpl type) { var parameter = ParameterElementImpl( name: name, nameOffset: 0, @@ -1201,7 +1201,7 @@ class _MockSdkElementsBuilder { TopLevelVariableElementImpl _topLevelVariableConst( String name, - DartType type, + TypeImpl type, ) { var fragment = ConstTopLevelVariableElementImpl(name, -1) ..isConst = true @@ -1215,7 +1215,7 @@ class _MockSdkElementsBuilder { return TypeParameterElementImpl(name, 0); } - TypeParameterType _typeParameterType(TypeParameterElement element) { + TypeParameterTypeImpl _typeParameterType(TypeParameterElement element) { return TypeParameterTypeImpl( element: element, nullabilitySuffix: NullabilitySuffix.none, diff --git a/pkg/analyzer/test/generated/elements_types_mixin.dart b/pkg/analyzer/test/generated/elements_types_mixin.dart index 2c0dd91d294d..d845879d5ab1 100644 --- a/pkg/analyzer/test/generated/elements_types_mixin.dart +++ b/pkg/analyzer/test/generated/elements_types_mixin.dart @@ -204,7 +204,7 @@ mixin ElementsTypesMixin { ExtensionTypeElementImpl extensionType( String name, { String representationName = 'it', - required DartType representationType, + required TypeImpl representationType, List typeParameters = const [], List interfaces = const [], }) { @@ -438,7 +438,7 @@ mixin ElementsTypesMixin { ParameterElementImpl namedParameter({ required String name, - required DartType type, + required TypeImpl type, bool isCovariant = false, }) { var parameter = ParameterElementImpl( @@ -453,7 +453,7 @@ mixin ElementsTypesMixin { ParameterElementImpl namedRequiredParameter({ required String name, - required DartType type, + required TypeImpl type, bool isCovariant = false, }) { var parameter = ParameterElementImpl( @@ -468,7 +468,7 @@ mixin ElementsTypesMixin { ParameterElementImpl positionalParameter({ String? name, - required DartType type, + required TypeImpl type, bool isCovariant = false, String? defaultValueCode, }) { @@ -562,7 +562,7 @@ mixin ElementsTypesMixin { ParameterElementImpl requiredParameter({ String? name, - required DartType type, + required TypeImpl type, bool isCovariant = false, }) { var parameter = ParameterElementImpl( diff --git a/pkg/analyzer/test/src/dart/element/element_test.dart b/pkg/analyzer/test/src/dart/element/element_test.dart index 2f8659697b31..04d62c985bcc 100644 --- a/pkg/analyzer/test/src/dart/element/element_test.dart +++ b/pkg/analyzer/test/src/dart/element/element_test.dart @@ -1222,7 +1222,7 @@ class InterfaceTypeImplTest extends AbstractTypeSystemTest with StringTypes { var AE = typeParameter('E'); var A = class_(name: 'A', typeParameters: [AE]); - DartType typeAE = typeParameterTypeNone(AE); + var typeAE = typeParameterTypeNone(AE); String getterName = "g"; PropertyAccessorElementImpl getterG = ElementFactory.getterElement(getterName, false, typeAE); @@ -1341,7 +1341,7 @@ A? // var E = typeParameter('E'); var A = class_(name: 'A', typeParameters: [E]); - DartType typeE = typeParameterTypeNone(E); + var typeE = typeParameterTypeNone(E); String methodName = "m"; MethodElementImpl methodM = ElementFactory.methodElement(methodName, typeE, [typeE]); @@ -1469,7 +1469,7 @@ A? // var E = typeParameter('E'); var A = class_(name: 'A', typeParameters: [E]); - DartType typeE = typeParameterTypeNone(E); + var typeE = typeParameterTypeNone(E); String setterName = "s"; PropertyAccessorElementImpl setterS = ElementFactory.setterElement(setterName, false, typeE); diff --git a/pkg/analyzer/test/src/dart/element/function_type_test.dart b/pkg/analyzer/test/src/dart/element/function_type_test.dart index 284e3f38abba..164ddc08607f 100644 --- a/pkg/analyzer/test/src/dart/element/function_type_test.dart +++ b/pkg/analyzer/test/src/dart/element/function_type_test.dart @@ -30,7 +30,7 @@ class FunctionTypeTest extends AbstractTypeSystemTest { ClassElement get mapElement => typeProvider.mapElement; - InterfaceType get objectType => typeProvider.objectType; + InterfaceTypeImpl get objectType => typeProvider.objectType; void basicChecks(FunctionType f, {displayName = 'dynamic Function()', diff --git a/pkg/analyzer/test/src/dart/element/least_greatest_closure_test.dart b/pkg/analyzer/test/src/dart/element/least_greatest_closure_test.dart index 17e4694cac9c..7dafa59e62a1 100644 --- a/pkg/analyzer/test/src/dart/element/least_greatest_closure_test.dart +++ b/pkg/analyzer/test/src/dart/element/least_greatest_closure_test.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/dart/element/element.dart'; +import 'package:analyzer/src/dart/element/type.dart'; import 'package:analyzer/src/utilities/extensions/element.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -21,7 +22,7 @@ main() { @reflectiveTest class GreatestClosureTest extends AbstractTypeSystemTest { late final TypeParameterElementImpl2 T; - late final TypeParameterType T_none; + late final TypeParameterTypeImpl T_none; late final TypeParameterType T_question; @override diff --git a/pkg/analyzer/test/src/dart/element/non_covariant_type_parameter_position_test.dart b/pkg/analyzer/test/src/dart/element/non_covariant_type_parameter_position_test.dart index e70f9263aeff..7e65d27df1da 100644 --- a/pkg/analyzer/test/src/dart/element/non_covariant_type_parameter_position_test.dart +++ b/pkg/analyzer/test/src/dart/element/non_covariant_type_parameter_position_test.dart @@ -5,6 +5,7 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart'; import 'package:analyzer/dart/element/type.dart'; import 'package:analyzer/src/dart/element/non_covariant_type_parameter_position.dart'; +import 'package:analyzer/src/dart/element/type.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -22,7 +23,7 @@ class NonCovariantTypeParameterPositionVisitorTest late final T_element = typeParameter('T'); late final T = typeParameterTypeNone(T_element); - FunctionType get _contravariantT { + FunctionTypeImpl get _contravariantT { return functionTypeNone( returnType: voidNone, parameters: [ diff --git a/pkg/analyzer/test/src/dart/element/replace_top_bottom_test.dart b/pkg/analyzer/test/src/dart/element/replace_top_bottom_test.dart index 48e3048fc634..3a0c68e25f58 100644 --- a/pkg/analyzer/test/src/dart/element/replace_top_bottom_test.dart +++ b/pkg/analyzer/test/src/dart/element/replace_top_bottom_test.dart @@ -5,6 +5,7 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/src/dart/element/type.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -22,7 +23,7 @@ class ReplaceTopBottomTest extends AbstractTypeSystemTest { // Not contravariant. _check(neverNone, 'Never'); - void checkContravariant(DartType type, String expectedStr) { + void checkContravariant(TypeImpl type, String expectedStr) { _check( functionTypeNone(returnType: intNone, parameters: [ requiredParameter(type: type), diff --git a/pkg/analyzer/test/src/dart/element/runtime_type_equality_test.dart b/pkg/analyzer/test/src/dart/element/runtime_type_equality_test.dart index 5c37bb73da34..a3b79883131f 100644 --- a/pkg/analyzer/test/src/dart/element/runtime_type_equality_test.dart +++ b/pkg/analyzer/test/src/dart/element/runtime_type_equality_test.dart @@ -6,6 +6,7 @@ import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/src/dart/element/type.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -55,8 +56,8 @@ class RuntimeTypeEqualityTypeTest extends AbstractTypeSystemTest { void checkRequiredParameter( - DartType T1_type, - DartType T2_type, + TypeImpl T1_type, + TypeImpl T2_type, bool expected, ) { check( diff --git a/pkg/analyzer/test/src/dart/element/type_references_any_test.dart b/pkg/analyzer/test/src/dart/element/type_references_any_test.dart index e841af2a80ae..c196d95cdeaa 100644 --- a/pkg/analyzer/test/src/dart/element/type_references_any_test.dart +++ b/pkg/analyzer/test/src/dart/element/type_references_any_test.dart @@ -21,7 +21,7 @@ main() { @reflectiveTest class TypeReferencesAnyTest extends AbstractTypeSystemTest { late TypeParameterElement T; - late TypeParameterType T_none; + late TypeParameterTypeImpl T_none; @override void setUp() { diff --git a/pkg/analyzer/test/src/dart/element/upper_lower_bound_test.dart b/pkg/analyzer/test/src/dart/element/upper_lower_bound_test.dart index 1d613d1016ec..8c86953c7758 100644 --- a/pkg/analyzer/test/src/dart/element/upper_lower_bound_test.dart +++ b/pkg/analyzer/test/src/dart/element/upper_lower_bound_test.dart @@ -8,6 +8,7 @@ import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations. import 'package:analyzer/dart/element/element.dart'; import 'package:analyzer/dart/element/nullability_suffix.dart'; import 'package:analyzer/dart/element/type.dart'; +import 'package:analyzer/src/dart/element/type.dart'; import 'package:analyzer/src/dart/element/type_schema.dart'; import 'package:analyzer/src/dart/element/type_system.dart'; import 'package:test/test.dart'; @@ -505,9 +506,9 @@ class LowerBoundTest extends _BoundsTestBase { test_functionType2_parameters_named() { FunctionType build( - List requiredTypes, - Map namedMap, - Map namedRequiredMap, + List requiredTypes, + Map namedMap, + Map namedRequiredMap, ) { var parameters = []; @@ -608,8 +609,8 @@ class LowerBoundTest extends _BoundsTestBase { test_functionType2_parameters_positional() { FunctionType build( - List requiredTypes, - List positionalTypes, + List requiredTypes, + List positionalTypes, ) { var parameters = []; @@ -801,7 +802,7 @@ class LowerBoundTest extends _BoundsTestBase { } test_futureOr() { - InterfaceType futureOrFunction(DartType T, String str) { + InterfaceType futureOrFunction(TypeImpl T, String str) { var result = futureOrNone( functionTypeNone(returnType: voidNone, parameters: [ requiredParameter(type: T), @@ -1488,7 +1489,7 @@ class UpperBound_FunctionTypes_Test extends _BoundsTestBase { } test_parameters_optionalNamed() { - FunctionType build(Map namedTypes) { + FunctionType build(Map namedTypes) { return functionTypeNone( returnType: voidNone, parameters: namedTypes.entries.map((entry) { @@ -1497,8 +1498,8 @@ class UpperBound_FunctionTypes_Test extends _BoundsTestBase { ); } - void check(Map T1_named, Map T2_named, - Map expected_named) { + void check(Map T1_named, Map T2_named, + Map expected_named) { var T1 = build(T1_named); var T2 = build(T2_named); var expected = build(expected_named); @@ -1515,7 +1516,7 @@ class UpperBound_FunctionTypes_Test extends _BoundsTestBase { } test_parameters_optionalPositional() { - FunctionType build(List positionalTypes) { + FunctionType build(List positionalTypes) { return functionTypeNone( returnType: voidNone, parameters: positionalTypes.map((type) { @@ -1524,7 +1525,7 @@ class UpperBound_FunctionTypes_Test extends _BoundsTestBase { ); } - void check(List T1_positional, List T2_positional, + void check(List T1_positional, List T2_positional, DartType expected) { var T1 = build(T1_positional); var T2 = build(T2_positional); @@ -1663,7 +1664,7 @@ class UpperBound_FunctionTypes_Test extends _BoundsTestBase { } test_parameters_requiredPositional() { - FunctionType build(List requiredTypes) { + FunctionType build(List requiredTypes) { return functionTypeNone( returnType: voidNone, parameters: requiredTypes.map((type) { @@ -1672,7 +1673,7 @@ class UpperBound_FunctionTypes_Test extends _BoundsTestBase { ); } - void check(List T1_required, List T2_required, + void check(List T1_required, List T2_required, DartType expected) { var T1 = build(T1_required); var T2 = build(T2_required);