Skip to content

Commit b5ff3b8

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use more TypeImpl around DartObjectImpl.
Change-Id: I8ffd64dd18ae3b88f6ca3474d1562794f14b09dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412342 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 2cc6b61 commit b5ff3b8

File tree

15 files changed

+86
-91
lines changed

15 files changed

+86
-91
lines changed

pkg/analyzer/lib/src/dart/ast/ast.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8772,7 +8772,7 @@ final class FunctionReferenceImpl extends CommentReferableExpressionImpl
87728772
TypeArgumentListImpl? _typeArguments;
87738773

87748774
@override
8775-
List<DartType>? typeArgumentTypes;
8775+
List<TypeImpl>? typeArgumentTypes;
87768776

87778777
FunctionReferenceImpl({
87788778
required ExpressionImpl function,
@@ -16114,7 +16114,7 @@ final class SimpleIdentifierImpl extends IdentifierImpl
1611416114
Element? _staticElement;
1611516115

1611616116
@override
16117-
List<DartType>? tearOffTypeArgumentTypes;
16117+
List<TypeImpl>? tearOffTypeArgumentTypes;
1611816118

1611916119
/// If this identifier is meant to be looked up in the enclosing scope, the
1612016120
/// raw result the scope lookup, prior to figuring out whether a write or a

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
297297
void visitListLiteral(ListLiteral node) {
298298
super.visitListLiteral(node);
299299
if (node.isConst) {
300-
var nodeType = node.staticType as InterfaceType;
300+
var nodeType = node.staticType as InterfaceTypeImpl;
301301
var elementType = nodeType.typeArguments[0];
302302
var verifier = _ConstLiteralVerifier(
303303
this,
@@ -395,7 +395,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
395395
super.visitSetOrMapLiteral(node);
396396
if (node.isSet) {
397397
if (node.isConst) {
398-
var nodeType = node.staticType as InterfaceType;
398+
var nodeType = node.staticType as InterfaceTypeImpl;
399399
var elementType = nodeType.typeArguments[0];
400400
var config = _SetVerifierConfig(elementType: elementType);
401401
var verifier = _ConstLiteralVerifier(
@@ -413,7 +413,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
413413
}
414414
} else if (node.isMap) {
415415
if (node.isConst) {
416-
var nodeType = node.staticType as InterfaceType;
416+
var nodeType = node.staticType as InterfaceTypeImpl;
417417
var keyType = nodeType.typeArguments[0];
418418
var valueType = nodeType.typeArguments[1];
419419
var config = _MapVerifierConfig(
@@ -1069,7 +1069,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
10691069
class _ConstLiteralVerifier {
10701070
final ConstantVerifier verifier;
10711071
final ErrorCode errorCode;
1072-
final DartType? listElementType;
1072+
final TypeImpl? listElementType;
10731073
final _SetVerifierConfig? setConfig;
10741074
final _MapVerifierConfig? mapConfig;
10751075

@@ -1228,7 +1228,7 @@ class _ConstLiteralVerifier {
12281228
}
12291229

12301230
bool _validateListExpression(
1231-
DartType listElementType, Expression expression, DartObjectImpl value) {
1231+
TypeImpl listElementType, Expression expression, DartObjectImpl value) {
12321232
if (!verifier._runtimeTypeMatch(value, listElementType)) {
12331233
if (verifier._runtimeTypeMatch(
12341234
value, verifier._typeSystem.makeNullable(listElementType))) {
@@ -1471,8 +1471,8 @@ class _ConstLiteralVerifier {
14711471
}
14721472

14731473
class _MapVerifierConfig {
1474-
final DartType keyType;
1475-
final DartType valueType;
1474+
final TypeImpl keyType;
1475+
final TypeImpl valueType;
14761476
final Map<DartObject, Expression> uniqueKeys = {};
14771477
final Map<Expression, Expression> duplicateKeys = {};
14781478

@@ -1483,7 +1483,7 @@ class _MapVerifierConfig {
14831483
}
14841484

14851485
class _SetVerifierConfig {
1486-
final DartType elementType;
1486+
final TypeImpl elementType;
14871487
final Map<DartObject, Expression> uniqueValues = {};
14881488
final Map<Expression, Expression> duplicateElements = {};
14891489

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class ConstantEvaluationEngine {
340340
Constant evaluateAndFormatErrorsInConstructorCall(
341341
LibraryElementImpl library,
342342
AstNode node,
343-
List<DartType>? typeArguments,
343+
List<TypeImpl>? typeArguments,
344344
List<Expression> arguments,
345345
ConstructorElementMixin constructor,
346346
ConstantVisitor constantVisitor, {
@@ -385,7 +385,7 @@ class ConstantEvaluationEngine {
385385
Constant evaluateConstructorCall(
386386
LibraryElementImpl library,
387387
AstNode node,
388-
List<DartType>? typeArguments,
388+
List<TypeImpl>? typeArguments,
389389
List<Expression> arguments,
390390
ConstructorElementMixin constructor,
391391
ConstantVisitor constantVisitor, {
@@ -544,7 +544,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
544544
final Map<String, DartObjectImpl>? _lexicalEnvironment;
545545

546546
/// A mapping of type parameter names to runtime values (types).
547-
final Map<TypeParameterElement, DartType>? _lexicalTypeEnvironment;
547+
final Map<TypeParameterElement, TypeImpl>? _lexicalTypeEnvironment;
548548

549549
final Substitution? _substitution;
550550

@@ -567,7 +567,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
567567
this._library,
568568
this._errorReporter, {
569569
Map<String, DartObjectImpl>? lexicalEnvironment,
570-
Map<TypeParameterElement, DartType>? lexicalTypeEnvironment,
570+
Map<TypeParameterElement, TypeImpl>? lexicalTypeEnvironment,
571571
Substitution? substitution,
572572
}) : _lexicalEnvironment = lexicalEnvironment,
573573
_lexicalTypeEnvironment = lexicalTypeEnvironment,
@@ -815,7 +815,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
815815
return InvalidConstant.forEntity(
816816
node, CompileTimeErrorCode.INVALID_CONSTANT);
817817
}
818-
var classType = constructorFunctionType.returnType as InterfaceType;
818+
var classType = constructorFunctionType.returnType as InterfaceTypeImpl;
819819
var typeArguments = classType.typeArguments;
820820
// The result is already instantiated during resolution;
821821
// [_dartObjectComputer.typeInstantiate] is unnecessary.
@@ -858,7 +858,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
858858
}
859859

860860
@override
861-
Constant visitFunctionReference(FunctionReference node) {
861+
Constant visitFunctionReference(covariant FunctionReferenceImpl node) {
862862
var functionResult = evaluateConstant(node.function);
863863
if (functionResult is! DartObjectImpl) {
864864
return functionResult;
@@ -890,7 +890,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
890890
return _instantiateFunctionType(node, functionResult);
891891
}
892892

893-
var typeArguments = <DartType>[];
893+
var typeArguments = <TypeImpl>[];
894894
for (var typeArgument in typeArgumentList.arguments) {
895895
var typeArgumentConstant = evaluateConstant(typeArgument);
896896
switch (typeArgumentConstant) {
@@ -920,7 +920,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
920920
}
921921

922922
@override
923-
Constant visitGenericFunctionType(GenericFunctionType node) {
923+
Constant visitGenericFunctionType(covariant GenericFunctionTypeImpl node) {
924924
return DartObjectImpl(
925925
typeSystem,
926926
_typeProvider.typeType,
@@ -1108,7 +1108,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
11081108
evaluateConstant(node.expression);
11091109

11101110
@override
1111-
Constant visitPrefixedIdentifier(PrefixedIdentifier node) {
1111+
Constant visitPrefixedIdentifier(covariant PrefixedIdentifierImpl node) {
11121112
var prefixNode = node.prefix;
11131113
var prefixElement = prefixNode.staticElement;
11141114

@@ -1177,10 +1177,10 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
11771177
}
11781178

11791179
@override
1180-
Constant visitPropertyAccess(PropertyAccess node) {
1180+
Constant visitPropertyAccess(covariant PropertyAccessImpl node) {
11811181
var target = node.target;
11821182
if (target != null) {
1183-
if (target is PrefixedIdentifier &&
1183+
if (target is PrefixedIdentifierImpl &&
11841184
(target.staticElement is ExtensionElement ||
11851185
target.staticElement is ExtensionTypeElement)) {
11861186
var prefix = target.prefix;
@@ -1247,7 +1247,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
12471247
}
12481248

12491249
@override
1250-
Constant? visitRecordTypeAnnotation(RecordTypeAnnotation node) {
1250+
Constant? visitRecordTypeAnnotation(covariant RecordTypeAnnotationImpl node) {
12511251
return DartObjectImpl(
12521252
typeSystem,
12531253
_typeProvider.typeType,
@@ -1307,7 +1307,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
13071307
}
13081308

13091309
@override
1310-
Constant visitSimpleIdentifier(SimpleIdentifier node) {
1310+
Constant visitSimpleIdentifier(covariant SimpleIdentifierImpl node) {
13111311
var value = _lexicalEnvironment?[node.name];
13121312
if (value != null) {
13131313
return _instantiateFunctionTypeForSimpleIdentifier(node, value);
@@ -1727,9 +1727,9 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
17271727
Constant _getConstantValue({
17281728
required AstNode errorNode,
17291729
required Expression? expression,
1730-
required SimpleIdentifier? identifier,
1730+
required SimpleIdentifierImpl? identifier,
17311731
required Element? element,
1732-
DartType? givenType,
1732+
TypeImpl? givenType,
17331733
}) {
17341734
var errorNode2 = _evaluationEngine.configuration.errorNode(errorNode);
17351735
element = element?.declaration;
@@ -1795,7 +1795,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
17951795
}
17961796
return _instantiateFunctionTypeForSimpleIdentifier(identifier, rawType);
17971797
}
1798-
} else if (variableElement is InterfaceElement) {
1798+
} else if (variableElement is InterfaceElementImpl) {
17991799
var type = givenType ??
18001800
variableElement.instantiate(
18011801
typeArguments: variableElement.typeParameters
@@ -1814,7 +1814,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
18141814
_typeProvider.typeType,
18151815
TypeState(_typeProvider.dynamicType),
18161816
);
1817-
} else if (variableElement is TypeAliasElement) {
1817+
} else if (variableElement is TypeAliasElementImpl) {
18181818
var type = givenType ??
18191819
variableElement.instantiate(
18201820
typeArguments: variableElement.typeParameters
@@ -1928,7 +1928,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19281928
/// argument types, returns [value] type-instantiated with those [node]'s
19291929
/// type argument types, otherwise returns [value].
19301930
DartObjectImpl _instantiateFunctionType(
1931-
FunctionReference node, DartObjectImpl value) {
1931+
FunctionReferenceImpl node, DartObjectImpl value) {
19321932
var functionElement = value.toFunctionValue();
19331933
if (functionElement is! ExecutableElementOrMember) {
19341934
return value;
@@ -1956,7 +1956,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19561956
/// type-instantiated with those [node]'s tear-off type argument types,
19571957
/// otherwise returns [value].
19581958
Constant _instantiateFunctionTypeForSimpleIdentifier(
1959-
SimpleIdentifier node, DartObjectImpl value) {
1959+
SimpleIdentifierImpl node, DartObjectImpl value) {
19601960
// TODO(srawlins): When all code uses [FunctionReference]s generated via
19611961
// generic function instantiation, remove this method and all call sites.
19621962
var functionElement = value.toFunctionValue();
@@ -2298,7 +2298,7 @@ class DartObjectComputer {
22982298

22992299
Constant typeInstantiate(
23002300
DartObjectImpl function,
2301-
List<DartType> typeArguments,
2301+
List<TypeImpl> typeArguments,
23022302
Expression node,
23032303
TypeArgumentList typeArgumentsErrorNode,
23042304
) {
@@ -2430,7 +2430,7 @@ class _InstanceCreationEvaluator {
24302430

24312431
final ConstructorElementMixin _constructor;
24322432

2433-
final List<DartType>? _typeArguments;
2433+
final List<TypeImpl>? _typeArguments;
24342434

24352435
final ConstructorInvocation _invocation;
24362436

@@ -2440,7 +2440,7 @@ class _InstanceCreationEvaluator {
24402440

24412441
final List<DartObjectImpl> _argumentValues;
24422442

2443-
final Map<TypeParameterElement, DartType> _typeParameterMap = HashMap();
2443+
final Map<TypeParameterElement, TypeImpl> _typeParameterMap = HashMap();
24442444

24452445
final Map<String, DartObjectImpl> _parameterMap = HashMap();
24462446

@@ -3056,7 +3056,7 @@ class _InstanceCreationEvaluator {
30563056
LibraryElementImpl library,
30573057
AstNode node,
30583058
ConstructorElementMixin constructor,
3059-
List<DartType>? typeArguments,
3059+
List<TypeImpl>? typeArguments,
30603060
List<Expression> arguments,
30613061
ConstantVisitor constantVisitor, {
30623062
ConstructorInvocation? invocation,

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ class DartObjectImpl implements DartObject, Constant {
985985
}
986986

987987
@override
988-
DartType? toTypeValue() {
988+
TypeImpl? toTypeValue() {
989989
var state = this.state;
990990
if (state is TypeState) {
991991
return state._type;
@@ -999,7 +999,7 @@ class DartObjectImpl implements DartObject, Constant {
999999
DartObjectImpl typeInstantiate(
10001000
TypeSystemImpl typeSystem,
10011001
FunctionTypeImpl type,
1002-
List<DartType> typeArguments,
1002+
List<TypeImpl> typeArguments,
10031003
) {
10041004
var functionState = state as FunctionState;
10051005
return DartObjectImpl(
@@ -1356,7 +1356,7 @@ class FunctionState extends InstanceState {
13561356
/// The element representing the function being modeled.
13571357
final ExecutableElementImpl2 element;
13581358

1359-
final List<DartType>? typeArguments;
1359+
final List<TypeImpl>? typeArguments;
13601360

13611361
/// The type alias which was referenced when tearing off a constructor,
13621362
/// if this function is a constructor tear-off, referenced via a type alias,
@@ -2527,20 +2527,20 @@ class InvalidConstant implements Constant {
25272527

25282528
/// The state of an object representing a list.
25292529
class ListState extends InstanceState {
2530-
final DartType elementType;
2530+
final TypeImpl elementType;
25312531
final List<DartObjectImpl> elements;
25322532

25332533
@override
25342534
final bool isUnknown;
25352535

25362536
ListState({
2537-
required DartType elementType,
2537+
required TypeImpl elementType,
25382538
required this.elements,
25392539
this.isUnknown = false,
25402540
}) : elementType = elementType.extensionTypeErasure;
25412541

25422542
/// Creates a state that represents a list whose value is not known.
2543-
factory ListState.unknown(DartType elementType) =>
2543+
factory ListState.unknown(TypeImpl elementType) =>
25442544
ListState(elementType: elementType, elements: [], isUnknown: true);
25452545

25462546
@override
@@ -2620,9 +2620,9 @@ class ListState extends InstanceState {
26202620

26212621
/// The state of an object representing a map.
26222622
class MapState extends InstanceState {
2623-
final DartType _keyType;
2623+
final TypeImpl _keyType;
26242624

2625-
final DartType _valueType;
2625+
final TypeImpl _valueType;
26262626

26272627
/// The entries in the map.
26282628
final Map<DartObjectImpl, DartObjectImpl> entries;
@@ -2633,16 +2633,16 @@ class MapState extends InstanceState {
26332633
/// Initializes a newly created state to represent a set with the given
26342634
/// [entries].
26352635
MapState({
2636-
required DartType keyType,
2637-
required DartType valueType,
2636+
required TypeImpl keyType,
2637+
required TypeImpl valueType,
26382638
required this.entries,
26392639
bool isUnknown = false,
26402640
}) : _keyType = keyType.extensionTypeErasure,
26412641
_valueType = valueType.extensionTypeErasure,
26422642
_isUnknown = isUnknown;
26432643

26442644
/// Creates a state that represents a map whose value is not known.
2645-
factory MapState.unknown(DartType keyType, DartType valueType) => MapState(
2645+
factory MapState.unknown(TypeImpl keyType, TypeImpl valueType) => MapState(
26462646
keyType: keyType, valueType: valueType, entries: {}, isUnknown: true);
26472647

26482648
@override
@@ -2923,7 +2923,7 @@ class RecordState extends InstanceState {
29232923

29242924
/// The state of an object representing a set.
29252925
class SetState extends InstanceState {
2926-
final DartType _elementType;
2926+
final TypeImpl _elementType;
29272927

29282928
/// The elements of the set.
29292929
final Set<DartObjectImpl> elements;
@@ -2934,14 +2934,14 @@ class SetState extends InstanceState {
29342934
/// Initializes a newly created state to represent a set with the given
29352935
/// [elements].
29362936
SetState({
2937-
required DartType elementType,
2937+
required TypeImpl elementType,
29382938
required this.elements,
29392939
bool isUnknown = false,
29402940
}) : _elementType = elementType.extensionTypeErasure,
29412941
_isUnknown = isUnknown;
29422942

29432943
/// Creates a state that represents a list whose value is not known.
2944-
factory SetState.unknown(DartType elementType) =>
2944+
factory SetState.unknown(TypeImpl elementType) =>
29452945
SetState(elementType: elementType, elements: {}, isUnknown: true);
29462946

29472947
@override
@@ -3158,9 +3158,9 @@ class SymbolState extends InstanceState {
31583158
/// The state of an object representing a type.
31593159
class TypeState extends InstanceState {
31603160
/// The element representing the type being modeled.
3161-
final DartType? _type;
3161+
final TypeImpl? _type;
31623162

3163-
factory TypeState(DartType? type) {
3163+
factory TypeState(TypeImpl? type) {
31643164
type = type?.extensionTypeErasure;
31653165
return TypeState._(type);
31663166
}

0 commit comments

Comments
 (0)