Skip to content

Commit c69114c

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use TypeImpl in more places.
Change-Id: Ie48ade90d01eaad80dc1842ca41cc25ca56c56ad Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411882 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent ec8f193 commit c69114c

14 files changed

+107
-115
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
518518
/// equality.
519519
bool _canBeEqual(DartType constantType, DartType valueType) {
520520
if (constantType is InterfaceType) {
521-
if (valueType is InterfaceType) {
521+
if (valueType is InterfaceTypeImpl) {
522522
if (constantType.isDartCoreInt && valueType.isDartCoreDouble) {
523523
return true;
524524
}

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import 'package:analyzer/src/dart/element/type_system.dart';
1111

1212
class LeastGreatestClosureHelper extends ReplacementVisitor {
1313
final TypeSystemImpl typeSystem;
14-
final DartType topType;
15-
final DartType topFunctionType;
16-
final DartType bottomType;
14+
final TypeImpl topType;
15+
final TypeImpl topFunctionType;
16+
final TypeImpl bottomType;
1717
final Set<TypeParameterElementImpl2> eliminationTargets;
1818

1919
late final bool _isLeastClosure;
@@ -27,14 +27,14 @@ class LeastGreatestClosureHelper extends ReplacementVisitor {
2727
required this.eliminationTargets,
2828
});
2929

30-
DartType get _functionReplacement {
30+
TypeImpl get _functionReplacement {
3131
return _isLeastClosure && _isCovariant ||
3232
(!_isLeastClosure && !_isCovariant)
3333
? bottomType
3434
: topFunctionType;
3535
}
3636

37-
DartType get _typeParameterReplacement {
37+
TypeImpl get _typeParameterReplacement {
3838
return _isLeastClosure && _isCovariant ||
3939
(!_isLeastClosure && !_isCovariant)
4040
? bottomType
@@ -47,27 +47,21 @@ class LeastGreatestClosureHelper extends ReplacementVisitor {
4747
}
4848

4949
/// Returns a supertype of [type] for all values of [eliminationTargets].
50-
TypeImpl eliminateToGreatest(DartType type) {
50+
TypeImpl eliminateToGreatest(TypeImpl type) {
5151
_isCovariant = true;
5252
_isLeastClosure = false;
53-
// TODO(paulberry): make this cast unnecessary by changing the type of
54-
// `type` and by changing `ReplacementVisitor` to implement
55-
// `TypeVisitor<TypeImpl?>`.
56-
return (type.accept(this) ?? type) as TypeImpl;
53+
return type.accept(this) ?? type;
5754
}
5855

5956
/// Returns a subtype of [type] for all values of [eliminationTargets].
60-
TypeImpl eliminateToLeast(DartType type) {
57+
TypeImpl eliminateToLeast(TypeImpl type) {
6158
_isCovariant = true;
6259
_isLeastClosure = true;
63-
// TODO(paulberry): make this cast unnecessary by changing the type of
64-
// `type` and by changing `ReplacementVisitor` to implement
65-
// `TypeVisitor<TypeImpl?>`.
66-
return (type.accept(this) ?? type) as TypeImpl;
60+
return type.accept(this) ?? type;
6761
}
6862

6963
@override
70-
DartType? visitFunctionType(FunctionType node) {
64+
TypeImpl? visitFunctionType(FunctionType node) {
7165
// - if `S` is
7266
// `T Function<X0 extends B0, ...., Xk extends Bk>(T0 x0, ...., Tn xn,
7367
// [Tn+1 xn+1, ..., Tm xm])`
@@ -87,9 +81,9 @@ class LeastGreatestClosureHelper extends ReplacementVisitor {
8781
}
8882

8983
@override
90-
DartType? visitTypeParameterType(TypeParameterType type) {
84+
TypeImpl? visitTypeParameterType(TypeParameterType type) {
9185
if (eliminationTargets.contains(type.element3)) {
92-
var replacement = _typeParameterReplacement as TypeImpl;
86+
var replacement = _typeParameterReplacement;
9387
return replacement.withNullability(
9488
uniteNullabilities(
9589
replacement.nullabilitySuffix,
@@ -117,13 +111,13 @@ class PatternGreatestClosureHelper extends ReplacementVisitor {
117111
}
118112

119113
/// Returns a supertype of [type] for all values of type parameters.
120-
DartType eliminateToGreatest(DartType type) {
114+
TypeImpl eliminateToGreatest(TypeImpl type) {
121115
_isCovariant = true;
122116
return type.accept(this) ?? type;
123117
}
124118

125119
@override
126-
DartType? visitTypeParameterType(TypeParameterType type) {
120+
TypeImpl? visitTypeParameterType(TypeParameterType type) {
127121
var replacement = _isCovariant ? topType : bottomType;
128122
return replacement.withNullability(
129123
uniteNullabilities(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ class LeastUpperBoundHelper {
846846
}
847847

848848
/// Return the promoted or declared bound of the type parameter.
849-
DartType _typeParameterBound(TypeParameterTypeImpl type) {
849+
TypeImpl _typeParameterBound(TypeParameterTypeImpl type) {
850850
var bound = type.promotedBound ?? type.element3.bound;
851851
if (bound != null) {
852852
return bound;

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'package:analyzer/dart/element/element2.dart';
66
import 'package:analyzer/dart/element/nullability_suffix.dart';
77
import 'package:analyzer/dart/element/type.dart';
8+
import 'package:analyzer/src/dart/element/element.dart';
89
import 'package:analyzer/src/dart/element/extensions.dart';
910
import 'package:analyzer/src/dart/element/type.dart';
1011
import 'package:analyzer/src/dart/element/type_algebra.dart';
@@ -24,15 +25,15 @@ class NormalizeHelper {
2425

2526
NormalizeHelper(this.typeSystem) : typeProvider = typeSystem.typeProvider;
2627

27-
DartType normalize(DartType T) {
28+
TypeImpl normalize(TypeImpl T) {
2829
return _normalize(T);
2930
}
3031

3132
/// `NORM(R Function<X extends B>(S)) = R1 Function(X extends B1>(S1)`
3233
/// * where R1 = NORM(R)
3334
/// * and B1 = NORM(B)
3435
/// * and S1 = NORM(S)
35-
FunctionTypeImpl _functionType(FunctionType functionType) {
36+
FunctionTypeImpl _functionType(FunctionTypeImpl functionType) {
3637
var fresh = getFreshTypeParameters2(functionType.typeParameters);
3738
for (var typeParameter in fresh.freshTypeParameters) {
3839
var bound = typeParameter.firstFragment.bound;
@@ -56,7 +57,7 @@ class NormalizeHelper {
5657
}
5758

5859
/// `NORM(FutureOr<T>)`
59-
DartType _futureOr(InterfaceType T) {
60+
TypeImpl _futureOr(InterfaceTypeImpl T) {
6061
// * let S be NORM(T)
6162
var S = _normalize(T.typeArguments[0]);
6263
var S_nullability = S.nullabilitySuffix;
@@ -96,7 +97,7 @@ class NormalizeHelper {
9697
);
9798
}
9899

99-
DartType _normalize(DartType T) {
100+
TypeImpl _normalize(TypeImpl T) {
100101
var T_nullability = T.nullabilitySuffix;
101102

102103
// NORM(T) = T if T is primitive
@@ -105,14 +106,14 @@ class NormalizeHelper {
105106
identical(T, NeverTypeImpl.instance) ||
106107
identical(T, VoidTypeImpl.instance) ||
107108
T_nullability == NullabilitySuffix.none &&
108-
T is InterfaceType &&
109+
T is InterfaceTypeImpl &&
109110
T.typeArguments.isEmpty) {
110111
return T;
111112
}
112113

113114
// NORM(FutureOr<T>)
114115
if (T_nullability == NullabilitySuffix.none &&
115-
T is InterfaceType &&
116+
T is InterfaceTypeImpl &&
116117
T.isDartAsyncFutureOr) {
117118
return _futureOr(T);
118119
}
@@ -131,7 +132,7 @@ class NormalizeHelper {
131132
}
132133

133134
// NORM(C<T0, ..., Tn>) = C<R0, ..., Rn> where Ri is NORM(Ti)
134-
if (T is InterfaceType) {
135+
if (T is InterfaceTypeImpl) {
135136
return T.element3.instantiate(
136137
typeArguments: T.typeArguments.map(_normalize).toFixedList(),
137138
nullabilitySuffix: NullabilitySuffix.none,
@@ -157,13 +158,13 @@ class NormalizeHelper {
157158
}
158159

159160
// NORM(R Function<X extends B>(S)) = R1 Function(X extends B1>(S1)
160-
return _functionType(T as FunctionType);
161+
return _functionType(T as FunctionTypeImpl);
161162
}
162163

163164
/// NORM(T?)
164-
DartType _nullabilityQuestion(DartType T) {
165+
TypeImpl _nullabilityQuestion(TypeImpl T) {
165166
// * let S be NORM(T)
166-
var T_none = (T as TypeImpl).withNullability(NullabilitySuffix.none);
167+
var T_none = T.withNullability(NullabilitySuffix.none);
167168
var S = _normalize(T_none);
168169
var S_nullability = S.nullabilitySuffix;
169170

@@ -184,7 +185,7 @@ class NormalizeHelper {
184185

185186
// * if S is FutureOr<R> and R is nullable then S
186187
if (S_nullability == NullabilitySuffix.none &&
187-
S is InterfaceType &&
188+
S is InterfaceTypeImpl &&
188189
S.isDartAsyncFutureOr) {
189190
var R = S.typeArguments[0];
190191
if (typeSystem.isNullable(R)) {
@@ -194,12 +195,12 @@ class NormalizeHelper {
194195

195196
// * if S is R? then R?
196197
// * else S?
197-
return (S as TypeImpl).withNullability(NullabilitySuffix.question);
198+
return S.withNullability(NullabilitySuffix.question);
198199
}
199200

200201
/// NORM(X & T)
201202
/// NORM(X extends T)
202-
DartType _typeParameterType(TypeParameterTypeImpl T) {
203+
TypeImpl _typeParameterType(TypeParameterTypeImpl T) {
203204
var element = T.element3;
204205

205206
// NORM(X & T)
@@ -235,7 +236,8 @@ class NormalizeHelper {
235236

236237
/// NORM(X & T)
237238
/// * let S be NORM(T)
238-
DartType _typeParameterType_promoted(TypeParameterElement2 X, DartType S) {
239+
TypeImpl _typeParameterType_promoted(
240+
TypeParameterElementImpl2 X, DartType S) {
239241
// * if S is Never then Never
240242
if (identical(S, NeverTypeImpl.instance)) {
241243
return NeverTypeImpl.instance;

0 commit comments

Comments
 (0)