Skip to content

Commit 1739d87

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Use TypeImpl in DartObjectImpl.
Change-Id: I95f5cc61b4c545abdd934375cf681fa59ede316f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412182 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 19c78e2 commit 1739d87

File tree

18 files changed

+96
-95
lines changed

18 files changed

+96
-95
lines changed

pkg/analyzer/lib/src/dart/analysis/results.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'package:analyzer/file_system/file_system.dart';
1717
import 'package:analyzer/source/line_info.dart';
1818
import 'package:analyzer/src/dart/analysis/file_state.dart';
1919
import 'package:analyzer/src/dart/element/element.dart';
20+
import 'package:analyzer/src/dart/element/type_provider.dart';
2021
import 'package:analyzer/src/dart/element/type_system.dart';
2122
import 'package:analyzer/src/generated/engine.dart';
2223

@@ -519,7 +520,7 @@ class ResolvedUnitResultImpl extends FileResultImpl
519520
LibraryFragment get libraryFragment => unit.declaredFragment!;
520521

521522
@override
522-
TypeProvider get typeProvider => libraryElement.typeProvider;
523+
TypeProviderImpl get typeProvider => libraryElement.typeProvider;
523524

524525
@override
525526
TypeSystemImpl get typeSystem => libraryElement.typeSystem;

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4502,7 +4502,7 @@ final class ConstructorNameImpl extends AstNodeImpl implements ConstructorName {
45024502
SimpleIdentifierImpl? _name;
45034503

45044504
@override
4505-
ConstructorElement? staticElement;
4505+
ConstructorElementMixin? staticElement;
45064506

45074507
/// Initializes a newly created constructor name.
45084508
///
@@ -4523,9 +4523,9 @@ final class ConstructorNameImpl extends AstNodeImpl implements ConstructorName {
45234523

45244524
@experimental
45254525
@override
4526-
ConstructorElement2? get element => staticElement?.asElement2;
4526+
ConstructorElementMixin2? get element => staticElement?.asElement2;
45274527

4528-
set element(ConstructorElement2? element) {
4528+
set element(ConstructorElementMixin2? element) {
45294529
staticElement = element?.asElement;
45304530
}
45314531

@@ -12578,9 +12578,9 @@ final class NamedExpressionImpl extends ExpressionImpl
1257812578
Token get beginToken => _name.beginToken;
1257912579

1258012580
@override
12581-
ParameterElement? get element {
12581+
ParameterElementMixin? get element {
1258212582
var element = _name.label.staticElement;
12583-
if (element is ParameterElement) {
12583+
if (element is ParameterElementMixin) {
1258412584
return element;
1258512585
}
1258612586
return null;
@@ -16814,7 +16814,7 @@ final class SuperConstructorInvocationImpl extends ConstructorInitializerImpl
1681416814
ArgumentListImpl _argumentList;
1681516815

1681616816
@override
16817-
ConstructorElement? staticElement;
16817+
ConstructorElementMixin? staticElement;
1681816818

1681916819
/// Initializes a newly created super invocation to invoke the inherited
1682016820
/// constructor with the given name with the given arguments.
@@ -16851,9 +16851,9 @@ final class SuperConstructorInvocationImpl extends ConstructorInitializerImpl
1685116851

1685216852
@experimental
1685316853
@override
16854-
ConstructorElement2? get element => staticElement?.asElement2;
16854+
ConstructorElementMixin2? get element => staticElement?.asElement2;
1685516855

16856-
set element(ConstructorElement2? value) {
16856+
set element(ConstructorElementMixin2? value) {
1685716857
staticElement = value?.asElement;
1685816858
}
1685916859

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import 'package:analyzer/dart/constant/value.dart';
1717
import 'package:analyzer/dart/element/element.dart';
1818
import 'package:analyzer/dart/element/nullability_suffix.dart';
1919
import 'package:analyzer/dart/element/type.dart';
20-
import 'package:analyzer/dart/element/type_provider.dart';
2120
import 'package:analyzer/error/error.dart';
2221
import 'package:analyzer/error/listener.dart';
2322
import 'package:analyzer/src/dart/ast/ast.dart';
@@ -29,6 +28,7 @@ import 'package:analyzer/src/dart/constant/value.dart';
2928
import 'package:analyzer/src/dart/element/element.dart';
3029
import 'package:analyzer/src/dart/element/least_greatest_closure.dart';
3130
import 'package:analyzer/src/dart/element/type.dart';
31+
import 'package:analyzer/src/dart/element/type_provider.dart';
3232
import 'package:analyzer/src/dart/element/type_system.dart';
3333
import 'package:analyzer/src/diagnostic/diagnostic_factory.dart';
3434
import 'package:analyzer/src/error/codes.dart';
@@ -47,7 +47,7 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
4747
final TypeSystemImpl _typeSystem;
4848

4949
/// The type provider used to access the known types.
50-
final TypeProvider _typeProvider;
50+
final TypeProviderImpl _typeProvider;
5151

5252
/// The current library that is being analyzed.
5353
final LibraryElementImpl _currentLibrary;
@@ -252,7 +252,8 @@ class ConstantVerifier extends RecursiveAstVisitor<void> {
252252
}
253253

254254
@override
255-
void visitInstanceCreationExpression(InstanceCreationExpression node) {
255+
void visitInstanceCreationExpression(
256+
covariant InstanceCreationExpressionImpl node) {
256257
if (node.isConst) {
257258
var namedType = node.constructorName.type;
258259
_checkForConstWithTypeParameters(

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

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import 'package:analyzer/dart/element/element.dart';
1616
import 'package:analyzer/dart/element/element2.dart';
1717
import 'package:analyzer/dart/element/nullability_suffix.dart';
1818
import 'package:analyzer/dart/element/type.dart';
19-
import 'package:analyzer/dart/element/type_provider.dart';
2019
import 'package:analyzer/error/listener.dart';
2120
import 'package:analyzer/src/dart/ast/ast.dart';
2221
import 'package:analyzer/src/dart/ast/extensions.dart';
@@ -30,6 +29,7 @@ import 'package:analyzer/src/dart/element/element.dart';
3029
import 'package:analyzer/src/dart/element/member.dart';
3130
import 'package:analyzer/src/dart/element/type.dart';
3231
import 'package:analyzer/src/dart/element/type_algebra.dart';
32+
import 'package:analyzer/src/dart/element/type_provider.dart';
3333
import 'package:analyzer/src/dart/element/type_system.dart' show TypeSystemImpl;
3434
import 'package:analyzer/src/diagnostic/diagnostic.dart';
3535
import 'package:analyzer/src/error/codes.dart';
@@ -182,7 +182,7 @@ class ConstantEvaluationEngine {
182182
// ignore it here.
183183
constant.evaluationResult = null;
184184
}
185-
} else if (element is ConstructorElement &&
185+
} else if (element is ConstructorElementMixin &&
186186
element.isConst &&
187187
constNode.arguments != null) {
188188
var errorListener = RecordingErrorListener();
@@ -342,7 +342,7 @@ class ConstantEvaluationEngine {
342342
AstNode node,
343343
List<DartType>? typeArguments,
344344
List<Expression> arguments,
345-
ConstructorElement constructor,
345+
ConstructorElementMixin constructor,
346346
ConstantVisitor constantVisitor, {
347347
ConstructorInvocation? invocation,
348348
}) {
@@ -387,7 +387,7 @@ class ConstantEvaluationEngine {
387387
AstNode node,
388388
List<DartType>? typeArguments,
389389
List<Expression> arguments,
390-
ConstructorElement constructor,
390+
ConstructorElementMixin constructor,
391391
ConstantVisitor constantVisitor, {
392392
ConstructorInvocation? invocation,
393393
}) {
@@ -446,8 +446,8 @@ class ConstantEvaluationEngine {
446446

447447
/// If [constructor] redirects to another const constructor, return the
448448
/// const constructor it redirects to. Otherwise return `null`.
449-
static ConstructorElement? getConstRedirectedConstructor(
450-
ConstructorElement constructor) {
449+
static ConstructorElementMixin? getConstRedirectedConstructor(
450+
ConstructorElementMixin constructor) {
451451
if (!constructor.isFactory) {
452452
return null;
453453
}
@@ -500,7 +500,7 @@ class ConstantEvaluationEngine {
500500
/// Returns the representation of a constant expression which has an
501501
/// [InvalidType], with the given [defaultType].
502502
static DartObjectImpl _unresolvedObject(
503-
LibraryElementImpl library, DartType defaultType) {
503+
LibraryElementImpl library, TypeImpl defaultType) {
504504
// TODO(kallentu): Use a better representation of an unresolved object that
505505
// doesn't need to rely on NullState.
506506
return DartObjectImpl(
@@ -582,7 +582,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
582582
TypeSystemImpl get typeSystem => _library.typeSystem;
583583

584584
/// Convenience getter to access the [_evaluationEngine]'s type provider.
585-
TypeProvider get _typeProvider => _library.typeProvider;
585+
TypeProviderImpl get _typeProvider => _library.typeProvider;
586586

587587
/// Evaluates and reports an error if the evaluation result of [node] is an
588588
/// [InvalidConstant].
@@ -929,7 +929,8 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
929929
}
930930

931931
@override
932-
Constant visitInstanceCreationExpression(InstanceCreationExpression node) {
932+
Constant visitInstanceCreationExpression(
933+
covariant InstanceCreationExpressionImpl node) {
933934
if (!node.isConst) {
934935
// TODO(srawlins): Use a specific error code.
935936
// https://github.com/dart-lang/sdk/issues/47061
@@ -1235,7 +1236,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
12351236
}
12361237
}
12371238

1238-
var nodeType = RecordType(
1239+
var nodeType = RecordTypeImpl.fromApi(
12391240
positional: positionalFields.map((e) => e.type).toList(),
12401241
named: namedFields.map((name, value) => MapEntry(name, value.type)),
12411242
nullabilitySuffix: NullabilitySuffix.none,
@@ -1271,7 +1272,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
12711272
var keyType = _typeProvider.dynamicType;
12721273
var valueType = _typeProvider.dynamicType;
12731274
var nodeType = node.staticType;
1274-
if (nodeType is InterfaceType) {
1275+
if (nodeType is InterfaceTypeImpl) {
12751276
var typeArguments = nodeType.typeArguments;
12761277
if (typeArguments.length >= 2) {
12771278
keyType = typeArguments[0];
@@ -1364,7 +1365,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
13641365
List<DartObjectImpl> list,
13651366
List<CollectionElement> elements,
13661367
TypeSystemImpl typeSystem,
1367-
InterfaceType listType,
1368+
InterfaceTypeImpl listType,
13681369
) {
13691370
for (var element in elements) {
13701371
switch (element) {
@@ -1458,7 +1459,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
14581459
Map<DartObjectImpl, DartObjectImpl> map,
14591460
List<CollectionElement> elements,
14601461
TypeSystemImpl typeSystem,
1461-
InterfaceType mapType,
1462+
InterfaceTypeImpl mapType,
14621463
) {
14631464
for (var element in elements) {
14641465
switch (element) {
@@ -1552,7 +1553,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
15521553
Set<DartObjectImpl> set,
15531554
List<CollectionElement> elements,
15541555
TypeSystemImpl typeSystem,
1555-
InterfaceType setType,
1556+
InterfaceTypeImpl setType,
15561557
) {
15571558
for (var element in elements) {
15581559
switch (element) {
@@ -1929,7 +1930,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19291930
DartObjectImpl _instantiateFunctionType(
19301931
FunctionReference node, DartObjectImpl value) {
19311932
var functionElement = value.toFunctionValue();
1932-
if (functionElement is! ExecutableElement) {
1933+
if (functionElement is! ExecutableElementOrMember) {
19331934
return value;
19341935
}
19351936
var valueType = functionElement.type;
@@ -1941,7 +1942,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19411942
var substitution = _substitution;
19421943
if (substitution != null) {
19431944
instantiatedType =
1944-
substitution.substituteType(instantiatedType) as FunctionType;
1945+
substitution.substituteType(instantiatedType) as FunctionTypeImpl;
19451946
}
19461947
return value.typeInstantiate(
19471948
typeSystem, instantiatedType, typeArgumentTypes);
@@ -1959,7 +1960,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19591960
// TODO(srawlins): When all code uses [FunctionReference]s generated via
19601961
// generic function instantiation, remove this method and all call sites.
19611962
var functionElement = value.toFunctionValue();
1962-
if (functionElement is! ExecutableElement) {
1963+
if (functionElement is! ExecutableElementOrMember) {
19631964
return value;
19641965
}
19651966
var valueType = functionElement.type;
@@ -1992,7 +1993,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
19921993

19931994
/// Return the value of the given [expression], or a representation of a fake
19941995
/// constant to continue the evaluation if the expression is unresolved.
1995-
Constant _valueOf(Expression expression, DartType defaultType) {
1996+
Constant _valueOf(Expression expression, TypeImpl defaultType) {
19961997
var expressionValue = evaluateConstant(expression);
19971998
switch (expressionValue) {
19981999
// TODO(kallentu): g3 relies on reporting errors found here, but also
@@ -2302,7 +2303,7 @@ class DartObjectComputer {
23022303
TypeArgumentList typeArgumentsErrorNode,
23032304
) {
23042305
var rawType = function.type;
2305-
if (rawType is FunctionType) {
2306+
if (rawType is FunctionTypeImpl) {
23062307
if (typeArguments.length != rawType.typeFormals.length) {
23072308
if (node is SimpleIdentifier) {
23082309
return InvalidConstant.forEntity(typeArgumentsErrorNode,
@@ -2427,7 +2428,7 @@ class _InstanceCreationEvaluator {
24272428
/// The node used for most error reporting.
24282429
final AstNode _errorNode;
24292430

2430-
final ConstructorElement _constructor;
2431+
final ConstructorElementMixin _constructor;
24312432

24322433
final List<DartType>? _typeArguments;
24332434

@@ -2466,11 +2467,11 @@ class _InstanceCreationEvaluator {
24662467
_argumentValues = argumentValues,
24672468
_invocation = invocation;
24682469

2469-
InterfaceType get definingType => _constructor.returnType;
2470+
InterfaceTypeImpl get definingType => _constructor.returnType;
24702471

24712472
DartObjectImpl? get firstArgument => _argumentValues[0];
24722473

2473-
TypeProvider get typeProvider => _library.typeProvider;
2474+
TypeProviderImpl get typeProvider => _library.typeProvider;
24742475

24752476
TypeSystemImpl get typeSystem => _library.typeSystem;
24762477

@@ -2649,7 +2650,7 @@ class _InstanceCreationEvaluator {
26492650
/// `null`. Returns `true` if the arguments are correct, `false` otherwise.
26502651
bool _checkFromEnvironmentArguments(
26512652
List<Expression> arguments,
2652-
InterfaceType expectedDefaultValueType,
2653+
InterfaceTypeImpl expectedDefaultValueType,
26532654
) {
26542655
var argumentCount = arguments.length;
26552656
if (argumentCount < 1 || argumentCount > 2) {
@@ -2685,7 +2686,7 @@ class _InstanceCreationEvaluator {
26852686
/// redirecting constructor invocation, an [InvalidConstant], or an
26862687
/// incomplete state for further evaluation.
26872688
_InitializersEvaluationResult _checkInitializers() {
2688-
var constructorBase = _constructor.declaration as ConstructorElementImpl;
2689+
var constructorBase = _constructor.declaration;
26892690
// If we encounter a superinitializer, store the name of the constructor,
26902691
// and the arguments.
26912692
String? superName;
@@ -2876,9 +2877,7 @@ class _InstanceCreationEvaluator {
28762877
// are handling an optional parameter that wasn't specified. So just
28772878
// direct error messages to the constructor call.
28782879
errorTarget ??= _errorNode;
2879-
if (argumentValue == null &&
2880-
baseParameter is ParameterElementImpl &&
2881-
baseParameter.isOptional) {
2880+
if (argumentValue == null && baseParameter.isOptional) {
28822881
// The parameter is an optional positional parameter for which no value
28832882
// was provided, so use the default value.
28842883
var evaluationResult = baseParameter.evaluationResult;
@@ -3056,7 +3055,7 @@ class _InstanceCreationEvaluator {
30563055
DeclaredVariables declaredVariables,
30573056
LibraryElementImpl library,
30583057
AstNode node,
3059-
ConstructorElement constructor,
3058+
ConstructorElementMixin constructor,
30603059
List<DartType>? typeArguments,
30613060
List<Expression> arguments,
30623061
ConstantVisitor constantVisitor, {
@@ -3074,7 +3073,7 @@ class _InstanceCreationEvaluator {
30743073
node, CompileTimeErrorCode.CONST_WITH_NON_CONST);
30753074
}
30763075

3077-
if (!(constructor.declaration as ConstructorElementImpl).isCycleFree) {
3076+
if (!constructor.declaration.isCycleFree) {
30783077
// It's not safe to evaluate this constructor, so bail out.
30793078
//
30803079
// Instead of reporting an error at the call-sites, we will report an
@@ -3095,7 +3094,7 @@ class _InstanceCreationEvaluator {
30953094
// Use the corresponding parameter type as the default value if
30963095
// an unresolved expression is evaluated. We do this to continue the
30973096
// rest of the evaluation without producing unrelated errors.
3098-
if (argument is NamedExpression) {
3097+
if (argument is NamedExpressionImpl) {
30993098
var parameterType = argument.element?.type ?? InvalidTypeImpl.instance;
31003099
var argumentConstant =
31013100
constantVisitor._valueOf(argument.expression, parameterType);
@@ -3156,8 +3155,8 @@ class _InstanceCreationEvaluator {
31563155
/// chain terminates. If there is a problem (e.g. a redirection can't be
31573156
/// found, or a cycle is encountered), the chain will be followed as far as
31583157
/// possible and then a const factory constructor will be returned.
3159-
static ConstructorElement _followConstantRedirectionChain(
3160-
ConstructorElement constructor) {
3158+
static ConstructorElementMixin _followConstantRedirectionChain(
3159+
ConstructorElementMixin constructor) {
31613160
var constructorsVisited = <ConstructorElement>{};
31623161
while (true) {
31633162
var redirectedConstructor =

0 commit comments

Comments
 (0)