Skip to content

Commit 115dcc9

Browse files
bwilkersonCommit Queue
authored andcommitted
[migration] constant/value.dart
Change-Id: Id1ed8bd41b8efb34124ddda93f1039215caf0651 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411362 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent b4194ea commit 115dcc9

File tree

5 files changed

+67
-62
lines changed

5 files changed

+67
-62
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ class ConstantEvaluationEngine {
426426
CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT,
427427
);
428428
(constant as VariableElementImpl).evaluationResult =
429-
InvalidConstant.forElement(
430-
constant, CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
429+
InvalidConstant.forElement(constant.asElement2!,
430+
CompileTimeErrorCode.RECURSIVE_COMPILE_TIME_CONSTANT);
431431
} else if (constant is ConstructorElement) {
432432
// We don't report cycle errors on constructor declarations here since
433433
// there is nowhere to put the error information.
@@ -842,8 +842,9 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
842842
return DartObjectImpl(
843843
typeSystem,
844844
node.typeOrThrow,
845-
FunctionState(constructorElement,
846-
typeArguments: typeArguments, viaTypeAlias: viaTypeAlias),
845+
FunctionState(constructorElement.asElement2,
846+
typeArguments: typeArguments,
847+
viaTypeAlias: viaTypeAlias.asElement2 as TypeDefiningElement2?),
847848
);
848849
}
849850

@@ -1778,14 +1779,14 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
17781779
return DartObjectImpl(
17791780
typeSystem,
17801781
expression.typeOrThrow,
1781-
FunctionState(variableElement),
1782+
FunctionState(variableElement.asElement2),
17821783
);
17831784
} else if (variableElement is ExecutableElementImpl) {
17841785
if (variableElement.isStatic) {
17851786
var rawType = DartObjectImpl(
17861787
typeSystem,
17871788
variableElement.type,
1788-
FunctionState(variableElement),
1789+
FunctionState(variableElement.asElement2),
17891790
);
17901791
if (identifier == null) {
17911792
return InvalidConstant.forEntity(
@@ -2710,7 +2711,7 @@ class _InstanceCreationEvaluator {
27102711
if (field == null) {
27112712
return _InitializersEvaluationResult(
27122713
InvalidConstant.forElement(
2713-
getter,
2714+
getter.asElement2,
27142715
CompileTimeErrorCode.CONST_EVAL_THROWS_EXCEPTION,
27152716
),
27162717
evaluationIsComplete: true,
@@ -3120,7 +3121,7 @@ class _InstanceCreationEvaluator {
31203121
}
31213122

31223123
invocation ??= ConstructorInvocation(
3123-
constructor,
3124+
constructor.asElement2,
31243125
argumentValues,
31253126
namedValues,
31263127
);

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

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ sealed class Constant {}
146146
/// Information about a const constructor invocation.
147147
class ConstructorInvocation {
148148
/// The constructor that was called.
149-
final ConstructorElement constructor;
149+
final ConstructorElement2 constructor2;
150150

151151
/// Values of specified arguments, actual values for positional, and `null`
152152
/// for named (which are provided as [namedArguments]).
@@ -156,10 +156,9 @@ class ConstructorInvocation {
156156
final Map<String, DartObjectImpl> namedArguments;
157157

158158
ConstructorInvocation(
159-
this.constructor, this._argumentValues, this.namedArguments);
159+
this.constructor2, this._argumentValues, this.namedArguments);
160160

161-
/// The constructor that was called.
162-
ConstructorElement2 get constructor2 => constructor.asElement2;
161+
ConstructorElement get constructor => constructor2.asElement;
163162

164163
/// The positional arguments passed to the constructor.
165164
List<DartObjectImpl> get positionalArguments {
@@ -906,13 +905,13 @@ class DartObjectImpl implements DartObject, Constant {
906905

907906
@override
908907
ExecutableElement? toFunctionValue() {
909-
var state = this.state;
910-
return state is FunctionState ? state.element : null;
908+
return toFunctionValue2().asElement;
911909
}
912910

913911
@override
914912
ExecutableElement2? toFunctionValue2() {
915-
return toFunctionValue().asElement2;
913+
var state = this.state;
914+
return state is FunctionState ? state.element : null;
916915
}
917916

918917
@override
@@ -1354,7 +1353,7 @@ class EvaluationException {
13541353
/// The state of an object representing a function.
13551354
class FunctionState extends InstanceState {
13561355
/// The element representing the function being modeled.
1357-
final ExecutableElementImpl element;
1356+
final ExecutableElementImpl2 element;
13581357

13591358
final List<DartType>? typeArguments;
13601359

@@ -1366,12 +1365,12 @@ class FunctionState extends InstanceState {
13661365
/// aliased class.
13671366
///
13681367
/// Otherwise null.
1369-
final TypeDefiningElement? _viaTypeAlias;
1368+
final TypeDefiningElement2? _viaTypeAlias;
13701369

13711370
/// Initialize a newly created state to represent the function with the given
13721371
/// [element].
13731372
FunctionState(this.element,
1374-
{this.typeArguments, TypeDefiningElement? viaTypeAlias})
1373+
{this.typeArguments, TypeDefiningElement2? viaTypeAlias})
13751374
: _viaTypeAlias = viaTypeAlias;
13761375

13771376
@override
@@ -1408,7 +1407,7 @@ class FunctionState extends InstanceState {
14081407
}
14091408

14101409
@override
1411-
StringState convertToString() => StringState(element.name);
1410+
StringState convertToString() => StringState(element.name3);
14121411

14131412
@override
14141413
BoolState equalEqual(TypeSystemImpl typeSystem, InstanceState rightOperand) {
@@ -1422,7 +1421,7 @@ class FunctionState extends InstanceState {
14221421
BoolState isIdentical(TypeSystemImpl typeSystem, InstanceState rightOperand) {
14231422
if (rightOperand is FunctionState) {
14241423
var otherElement = rightOperand.element;
1425-
if (element.declaration != otherElement.declaration) {
1424+
if (element.baseElement != otherElement.baseElement) {
14261425
return BoolState.FALSE_STATE;
14271426
}
14281427
if (_viaTypeAlias != rightOperand._viaTypeAlias) {
@@ -1451,7 +1450,7 @@ class FunctionState extends InstanceState {
14511450
}
14521451

14531452
@override
1454-
String toString() => element.name;
1453+
String toString() => element.name3 ?? '<unnamed>';
14551454
}
14561455

14571456
/// The state of an object representing a Dart object for which there is no more
@@ -1526,21 +1525,21 @@ class GenericState extends InstanceState {
15261525
bool hasPrimitiveEquality(FeatureSet featureSet) {
15271526
var type = _object.type;
15281527
if (type is InterfaceType) {
1529-
bool isFromDartCoreObject(ExecutableElement? element) {
1530-
var enclosing = element?.enclosingElement3;
1531-
return enclosing is ClassElement && enclosing.isDartCoreObject;
1528+
bool isFromDartCoreObject(ExecutableElement2? element) {
1529+
var enclosing = element?.enclosingElement2;
1530+
return enclosing is ClassElement2 && enclosing.isDartCoreObject;
15321531
}
15331532

1534-
var element = type.element;
1535-
var library = element.library;
1533+
var element = type.element3;
1534+
var library = element.library2;
15361535

1537-
var eqEq = type.lookUpMethod2('==', library, concrete: true);
1536+
var eqEq = type.lookUpMethod3('==', library, concrete: true);
15381537
if (!isFromDartCoreObject(eqEq)) {
15391538
return false;
15401539
}
15411540

15421541
if (featureSet.isEnabled(Feature.patterns)) {
1543-
var hash = type.lookUpGetter2('hashCode', library, concrete: true);
1542+
var hash = type.lookUpGetter3('hashCode', library, concrete: true);
15441543
if (!isFromDartCoreObject(hash)) {
15451544
return false;
15461545
}
@@ -2462,15 +2461,15 @@ class InvalidConstant implements Constant {
24622461
}
24632462

24642463
/// Creates a constant evaluation error associated with an [element].
2465-
InvalidConstant.forElement(Element element, ErrorCode errorCode,
2464+
InvalidConstant.forElement(Element2 element, ErrorCode errorCode,
24662465
{List<Object>? arguments,
24672466
List<DiagnosticMessage>? contextMessages,
24682467
bool avoidReporting = false,
24692468
bool isUnresolved = false,
24702469
bool isRuntimeException = false})
24712470
: this._(
2472-
element.nameLength,
2473-
element.nameOffset,
2471+
element.name3!.length,
2472+
element.firstFragment.nameOffset2 ?? -1,
24742473
errorCode,
24752474
arguments: arguments,
24762475
contextMessages: contextMessages,

0 commit comments

Comments
 (0)