Skip to content

Commit b8e4feb

Browse files
scheglovCommit Queue
authored andcommitted
Use mapFunctionType() and mapInterfaceType().
Change-Id: I40429adac947a86e2ff7c84ff6c8473f8c73f931 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417104 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 31e8fe7 commit b8e4feb

File tree

7 files changed

+18
-21
lines changed

7 files changed

+18
-21
lines changed

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2041,8 +2041,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
20412041
functionElement.type.instantiate(typeArgumentTypes);
20422042
var substitution = _substitution;
20432043
if (substitution != null) {
2044-
instantiatedType =
2045-
substitution.substituteType(instantiatedType) as FunctionTypeImpl;
2044+
instantiatedType = substitution.mapFunctionType(instantiatedType);
20462045
}
20472046
return value.typeInstantiate(
20482047
typeSystem, instantiatedType, typeArgumentTypes);

pkg/analyzer/lib/src/dart/element/class_hierarchy.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ class ClassHierarchy {
6363
var element = type.element3;
6464
var rawInterfaces = implementedInterfaces(element);
6565
for (var rawInterface in rawInterfaces) {
66-
var newInterface =
67-
substitution.substituteType(rawInterface) as InterfaceTypeImpl;
66+
var newInterface = substitution.mapInterfaceType(rawInterface);
6867
interfacesMerger.add(newInterface);
6968
}
7069
}

pkg/analyzer/lib/src/dart/element/member.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,7 @@ abstract class ExecutableMember extends Member
329329

330330
@override
331331
FunctionTypeImpl get type {
332-
if (_type != null) return _type!;
333-
334-
_type = substitution.substituteType(declaration.type) as FunctionTypeImpl;
335-
return _type!;
332+
return _type ??= substitution.mapFunctionType(declaration.type);
336333
}
337334

338335
@override

pkg/analyzer/lib/src/dart/element/subtype.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,7 @@ class SubtypeHelper {
466466
for (var interface in subElement.allSupertypes) {
467467
if (identical(interface.element3, superElement)) {
468468
var substitution = Substitution.fromInterfaceType(subType);
469-
var substitutedInterface =
470-
substitution.substituteType(interface) as InterfaceTypeImpl;
469+
var substitutedInterface = substitution.mapInterfaceType(interface);
471470
return _interfaceArguments(
472471
superElement,
473472
substitutedInterface,

pkg/analyzer/lib/src/dart/element/type.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -652,10 +652,11 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
652652
@override
653653
List<InterfaceTypeImpl> get allSupertypes {
654654
var substitution = Substitution.fromInterfaceType(this);
655-
return element3.allSupertypes
656-
.map((t) => (substitution.substituteType(t) as InterfaceTypeImpl)
657-
.withNullability(nullabilitySuffix))
658-
.toList();
655+
return element3.allSupertypes.map((interface) {
656+
return substitution
657+
.mapInterfaceType(interface)
658+
.withNullability(nullabilitySuffix);
659+
}).toList();
659660
}
660661

661662
@Deprecated('Use constructors2 instead')
@@ -823,8 +824,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
823824
return null;
824825
}
825826

826-
return (Substitution.fromInterfaceType(this).substituteType(supertype)
827-
as InterfaceTypeImpl)
827+
return Substitution.fromInterfaceType(this)
828+
.mapInterfaceType(supertype)
828829
.withNullability(nullabilitySuffix);
829830
}
830831

@@ -887,7 +888,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
887888
for (var rawInterface in element.allSupertypes) {
888889
if (rawInterface.element == targetElement) {
889890
var substitution = Substitution.fromInterfaceType(this);
890-
return substitution.substituteType(rawInterface) as InterfaceTypeImpl;
891+
return substitution.mapInterfaceType(rawInterface);
891892
}
892893
}
893894

@@ -903,7 +904,7 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
903904
for (var rawInterface in element3.allSupertypes) {
904905
if (rawInterface.element3 == targetElement) {
905906
var substitution = Substitution.fromInterfaceType(this);
906-
return substitution.substituteType(rawInterface) as InterfaceTypeImpl;
907+
return substitution.mapInterfaceType(rawInterface);
907908
}
908909
}
909910

pkg/analyzer/lib/src/dart/element/type_algebra.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ abstract class Substitution {
154154

155155
DartType? getSubstitute(TypeParameterElement2 parameter, bool upperBound);
156156

157+
FunctionTypeImpl mapFunctionType(FunctionType type) {
158+
return substituteType(type) as FunctionTypeImpl;
159+
}
160+
157161
InterfaceTypeImpl mapInterfaceType(InterfaceType type) {
158162
return substituteType(type) as InterfaceTypeImpl;
159163
}

pkg/analyzer/lib/src/dart/element/type_constraint_gatherer.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ class TypeConstraintGatherer extends shared.TypeConstraintGenerator<
192192
for (var interface in type.element3.allSupertypes) {
193193
if (interface.element3 == typeDeclaration) {
194194
var substitution = Substitution.fromInterfaceType(type);
195-
var substitutedInterface =
196-
substitution.substituteType(interface) as InterfaceTypeImpl;
197-
return substitutedInterface.typeArguments;
195+
return substitution.mapInterfaceType(interface).typeArguments;
198196
}
199197
}
200198
return null;

0 commit comments

Comments
 (0)