Skip to content

Commit f61ecec

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Change return type of some TypeSystemImpl methods.
The following methods of `TypeSystemImpl` have their return type changed from `DartType` to `TypeImpl`: - `flatten` - `greatestClosureOfSchema` - `leastClosureOfSchema` - `resolveToBound` 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: I9cf82a644b944f18bae9435ba68c896d45723281 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405062 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent 54981a4 commit f61ecec

File tree

4 files changed

+26
-15
lines changed

4 files changed

+26
-15
lines changed

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,18 @@ class TypeSystemImpl implements TypeSystem {
400400
}
401401

402402
@override
403-
DartType flatten(DartType T) {
404-
if (identical(T, UnknownInferredType.instance)) {
403+
TypeImpl flatten(DartType T) {
404+
// TODO(paulberry): remove this cast by making the parameter `T` covariant
405+
// and changing its type to `TypeImpl`.
406+
if (identical(T as TypeImpl, UnknownInferredType.instance)) {
405407
return T;
406408
}
407409

408410
// if T is S? then flatten(T) = flatten(S)?
409411
var nullabilitySuffix = T.nullabilitySuffix;
410412
if (nullabilitySuffix != NullabilitySuffix.none) {
411-
var S = (T as TypeImpl).withNullability(NullabilitySuffix.none);
412-
return (flatten(S) as TypeImpl).withNullability(nullabilitySuffix);
413+
var S = T.withNullability(NullabilitySuffix.none);
414+
return flatten(S).withNullability(nullabilitySuffix);
413415
}
414416

415417
// If T is X & S for some type variable X and type S then:
@@ -629,13 +631,15 @@ class TypeSystemImpl implements TypeSystem {
629631
///
630632
/// Note that the greatest closure of a type schema is always a supertype of
631633
/// any type which matches the schema.
632-
DartType greatestClosureOfSchema(DartType schema) {
634+
TypeImpl greatestClosureOfSchema(DartType schema) {
635+
// TODO(paulberry): remove this cast by making `ReplacementVisitor`
636+
// implement `TypeVisitor<TypeImpl?>`.
633637
return TypeSchemaEliminationVisitor.run(
634638
topType: objectQuestion,
635639
bottomType: NeverTypeImpl.instance,
636640
isLeastClosure: false,
637641
schema: schema,
638-
);
642+
) as TypeImpl;
639643
}
640644

641645
@override
@@ -1413,13 +1417,15 @@ class TypeSystemImpl implements TypeSystem {
14131417
///
14141418
/// Note that the least closure of a type schema is always a subtype of any
14151419
/// type which matches the schema.
1416-
DartType leastClosureOfSchema(DartType schema) {
1420+
TypeImpl leastClosureOfSchema(DartType schema) {
1421+
// TODO(paulberry): remove this cast by making `ReplacementVisitor`
1422+
// implement `TypeVisitor<TypeImpl?>`.
14171423
return TypeSchemaEliminationVisitor.run(
14181424
topType: objectQuestion,
14191425
bottomType: NeverTypeImpl.instance,
14201426
isLeastClosure: true,
14211427
schema: schema,
1422-
);
1428+
) as TypeImpl;
14231429
}
14241430

14251431
@override
@@ -1717,7 +1723,10 @@ class TypeSystemImpl implements TypeSystem {
17171723
}
17181724

17191725
@override
1720-
DartType resolveToBound(DartType type) {
1726+
TypeImpl resolveToBound(DartType type) {
1727+
// TODO(paulberry): remove this cast by making the parameter `T` covariant
1728+
// and changing its type to `TypeImpl`.
1729+
type as TypeImpl;
17211730
if (type is TypeParameterTypeImpl) {
17221731
var promotedBound = type.promotedBound;
17231732
if (promotedBound != null) {
@@ -1729,7 +1738,7 @@ class TypeSystemImpl implements TypeSystem {
17291738
return objectQuestion;
17301739
}
17311740

1732-
var resolved = resolveToBound(bound) as TypeImpl;
1741+
var resolved = resolveToBound(bound);
17331742

17341743
var newNullabilitySuffix = uniteNullabilities(
17351744
uniteNullabilities(

pkg/analyzer/lib/src/dart/resolver/comment_reference_resolver.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:analyzer/dart/element/type.dart';
99
import 'package:analyzer/src/dart/ast/ast.dart';
1010
import 'package:analyzer/src/dart/element/element.dart';
1111
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
12+
import 'package:analyzer/src/dart/element/type.dart';
1213
import 'package:analyzer/src/dart/element/type_provider.dart';
1314
import 'package:analyzer/src/dart/element/type_system.dart';
1415
import 'package:analyzer/src/dart/resolver/type_property_resolver.dart';
@@ -165,7 +166,7 @@ class CommentReferenceResolver {
165166
var extendedType = _typeSystem.resolveToBound(
166167
enclosingExtension.extendedType,
167168
);
168-
if (extendedType is InterfaceType) {
169+
if (extendedType is InterfaceTypeImpl) {
169170
enclosingType = extendedType;
170171
} else if (extendedType is FunctionType) {
171172
enclosingType = _typeProvider.functionType;

pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:analyzer/src/dart/ast/ast.dart';
1414
import 'package:analyzer/src/dart/element/element.dart';
1515
import 'package:analyzer/src/dart/element/extensions.dart';
1616
import 'package:analyzer/src/dart/element/inheritance_manager3.dart';
17+
import 'package:analyzer/src/dart/element/type.dart';
1718
import 'package:analyzer/src/dart/element/type_provider.dart';
1819
import 'package:analyzer/src/dart/element/type_system.dart';
1920
import 'package:analyzer/src/dart/resolver/extension_member_resolver.dart';
@@ -180,7 +181,7 @@ class TypePropertyResolver {
180181
} else {
181182
var receiverTypeResolved = _typeSystem.resolveToBound(receiverType);
182183

183-
if (receiverTypeResolved is InterfaceType) {
184+
if (receiverTypeResolved is InterfaceTypeImpl) {
184185
_lookupInterfaceType(receiverTypeResolved);
185186
if (_hasGetterOrSetter) {
186187
return _toResult();
@@ -193,7 +194,7 @@ class TypePropertyResolver {
193194
}
194195
}
195196

196-
if (receiverTypeResolved is FunctionType &&
197+
if (receiverTypeResolved is FunctionTypeImpl &&
197198
_name == FunctionElement.CALL_METHOD_NAME) {
198199
return ResolutionResult(
199200
needsGetterError: false,
@@ -209,7 +210,7 @@ class TypePropertyResolver {
209210
return _toResult();
210211
}
211212

212-
if (receiverTypeResolved is RecordType) {
213+
if (receiverTypeResolved is RecordTypeImpl) {
213214
var field = receiverTypeResolved.fieldByName(name);
214215
if (field != null) {
215216
return ResolutionResult(

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
12131213
}
12141214

12151215
var context = typeSystem.flatten(contextType);
1216-
if (context is! FunctionType || context.typeFormals.isNotEmpty) {
1216+
if (context is! FunctionTypeImpl || context.typeFormals.isNotEmpty) {
12171217
return expression;
12181218
}
12191219

0 commit comments

Comments
 (0)