Skip to content

Commit

Permalink
[analyzer] Change substitute methods to return TypeImpl.
Browse files Browse the repository at this point in the history
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
#59763.

Change-Id: Iaf4959cd7f6428d1dbe1b15089f7e2a30eff3495
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405080
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
  • Loading branch information
stereotype441 authored and Commit Queue committed Jan 18, 2025
1 parent b069a13 commit 7dc5a42
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -11042,7 +11042,7 @@ class TypeAliasElementImpl extends _ExistingElementImpl
),
);
} else {
return (type as TypeImpl).withNullability(resultNullability);
return type.withNullability(resultNullability);
}
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/analyzer/lib/src/dart/element/type_algebra.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 7dc5a42

Please sign in to comment.