From 7dc5a42d5eaf3a2017e030cfca01372c5d832deb Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Sat, 18 Jan 2025 08:38:20 -0800 Subject: [PATCH] [analyzer] Change substitute methods to return `TypeImpl`. The following methods are changed so that they return `TypeImpl` rather than `DartType`: - `FreshTypeParameters.substitute` - `Substitution.substituteType` - `_NullSubstitution.substituteType` 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: Iaf4959cd7f6428d1dbe1b15089f7e2a30eff3495 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405080 Reviewed-by: Konstantin Shcheglov Commit-Queue: Paul Berry --- pkg/analyzer/lib/src/dart/element/element.dart | 6 +++--- pkg/analyzer/lib/src/dart/element/type_algebra.dart | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart index 9dc6500703a3..85a12ff3ae46 100644 --- a/pkg/analyzer/lib/src/dart/element/element.dart +++ b/pkg/analyzer/lib/src/dart/element/element.dart @@ -11001,7 +11001,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl ? NullabilitySuffix.question : nullabilitySuffix; - if (type is FunctionType) { + if (type is FunctionTypeImpl) { return FunctionTypeImpl( typeFormals: type.typeFormals, parameters: type.parameters, @@ -11032,7 +11032,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl typeArguments: typeArguments, ), ); - } else if (type is TypeParameterType) { + } else if (type is TypeParameterTypeImpl) { return TypeParameterTypeImpl( element: type.element, nullabilitySuffix: resultNullability, @@ -11042,7 +11042,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl ), ); } else { - return (type as TypeImpl).withNullability(resultNullability); + return type.withNullability(resultNullability); } } diff --git a/pkg/analyzer/lib/src/dart/element/type_algebra.dart b/pkg/analyzer/lib/src/dart/element/type_algebra.dart index b622147a5d2e..4176dc72973d 100644 --- a/pkg/analyzer/lib/src/dart/element/type_algebra.dart +++ b/pkg/analyzer/lib/src/dart/element/type_algebra.dart @@ -180,7 +180,7 @@ class FreshTypeParameters { ); } - DartType substitute(DartType type) => substitution.substituteType(type); + TypeImpl substitute(DartType type) => substitution.substituteType(type); } /// Substitution that is based on the [map]. @@ -205,9 +205,9 @@ abstract class Substitution { return types.map(mapInterfaceType); } - DartType substituteType(DartType type, {bool contravariant = false}) { + TypeImpl substituteType(DartType type, {bool contravariant = false}) { var visitor = _TopSubstitutor(this, contravariant); - return type.accept(visitor); + return type.accept(visitor) as TypeImpl; } /// Substitutes both variables from [first] and [second], favoring those from @@ -390,7 +390,8 @@ class _NullSubstitution extends MapSubstitution { } @override - DartType substituteType(DartType type, {bool contravariant = false}) => type; + TypeImpl substituteType(DartType type, {bool contravariant = false}) => + type as TypeImpl; @override String toString() => "Substitution.empty";