Skip to content

Commit a10602b

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate InvocationInferenceHelper.
Change-Id: I58cf825e547378bc8eaee40bc24d77ca84627f8f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412381 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 6c68547 commit a10602b

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

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

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
// ignore_for_file: analyzer_use_new_elements
5+
/// @docImport 'package:analyzer/dart/element/element2.dart';
6+
library;
67

78
import 'package:analyzer/dart/analysis/features.dart';
8-
import 'package:analyzer/dart/element/element.dart';
99
import 'package:analyzer/dart/element/nullability_suffix.dart';
1010
import 'package:analyzer/dart/element/type.dart';
1111
import 'package:analyzer/error/listener.dart';
@@ -21,13 +21,13 @@ import 'package:analyzer/src/utilities/extensions/element.dart';
2121

2222
/// Information about a constructor element to instantiate.
2323
///
24-
/// If the target is a [ClassElement], the [element] is a raw
25-
/// [ConstructorElement] from the class, and [typeParameters] are the
24+
/// If the target is a [ClassElement2], the [element] is a raw
25+
/// [ConstructorElement2] from the class, and [typeParameters] are the
2626
/// type parameters of the class.
2727
///
28-
/// If the target is a [TypeAliasElement] with an [InterfaceType] as the
28+
/// If the target is a [TypeAliasElement2] with an [InterfaceType] as the
2929
/// aliased type, the [element] is a [ConstructorMember] created from the
30-
/// [ConstructorElement] of the corresponding class, and substituting
30+
/// [ConstructorElement2] of the corresponding class, and substituting
3131
/// the class type parameters with the type arguments specified in the alias,
3232
/// explicit types or the type parameters of the alias. The [typeParameters]
3333
/// are the type parameters of the alias.
@@ -87,32 +87,32 @@ class InvocationInferenceHelper {
8787
/// return the element and type parameters to infer. Otherwise return `null`.
8888
ConstructorElementToInfer? constructorElementToInfer({
8989
required ConstructorName constructorName,
90-
required LibraryElement definingLibrary,
90+
required LibraryElementImpl definingLibrary,
9191
}) {
92-
List<TypeParameterElementImpl> typeParameters;
93-
ConstructorElementMixin? rawElement;
92+
List<TypeParameterElementImpl2> typeParameters;
93+
ConstructorElementMixin2? rawElement;
9494

9595
var typeName = constructorName.type;
96-
var typeElement = typeName.element;
97-
if (typeElement is InterfaceElementImpl) {
98-
var augmented = typeElement.augmented;
99-
typeParameters = typeElement.typeParameters;
96+
var typeElement = typeName.element2;
97+
if (typeElement is InterfaceElementImpl2) {
98+
typeParameters = typeElement.typeParameters2;
10099
var constructorIdentifier = constructorName.name;
101100
if (constructorIdentifier == null) {
102-
rawElement = augmented.unnamedConstructor;
101+
rawElement = typeElement.unnamedConstructor2;
103102
} else {
104103
var name = constructorIdentifier.name;
105-
rawElement = augmented.getNamedConstructor(name);
106-
if (rawElement != null && !rawElement.isAccessibleIn(definingLibrary)) {
104+
rawElement = typeElement.getNamedConstructor2(name);
105+
if (rawElement != null &&
106+
!rawElement.isAccessibleIn2(definingLibrary)) {
107107
rawElement = null;
108108
}
109109
}
110-
} else if (typeElement is TypeAliasElementImpl) {
111-
typeParameters = typeElement.typeParameters;
110+
} else if (typeElement is TypeAliasElementImpl2) {
111+
typeParameters = typeElement.typeParameters2;
112112
var aliasedType = typeElement.aliasedType;
113113
if (aliasedType is InterfaceTypeImpl) {
114114
var constructorIdentifier = constructorName.name;
115-
rawElement = aliasedType.lookUpConstructor(
115+
rawElement = aliasedType.lookUpConstructor2(
116116
constructorIdentifier?.name,
117117
definingLibrary,
118118
);
@@ -124,9 +124,7 @@ class InvocationInferenceHelper {
124124
if (rawElement == null) {
125125
return null;
126126
}
127-
return ConstructorElementToInfer(
128-
typeParameters.map((e) => e.asElement2).toList(),
129-
rawElement.asElement2);
127+
return ConstructorElementToInfer(typeParameters, rawElement);
130128
}
131129

132130
/// Given an uninstantiated generic function type, referenced by the
@@ -159,7 +157,7 @@ class InvocationInferenceHelper {
159157

160158
/// Finish resolution of the [MethodInvocation].
161159
///
162-
/// We have already found the invoked [ExecutableElement], and the [rawType]
160+
/// We have already found the invoked [ExecutableElement2], and the [rawType]
163161
/// is its not yet instantiated type. Here we perform downwards inference,
164162
/// resolution of arguments, and upwards inference.
165163
void resolveMethodInvocation({

pkg/analyzer/test/src/dart/resolution/instance_creation_test.dart

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,15 @@ void f() {
145145
''');
146146

147147
var node = findNode.singleInstanceCreationExpression;
148+
// TODO(scheglov): should be `A<int>`
148149
assertResolvedNodeText(node, r'''
149150
InstanceCreationExpression
150151
constructorName: ConstructorName
151152
type: NamedType
152153
name: A
153154
element: <testLibraryFragment>::@class::A
154155
element2: <testLibrary>::@class::A
155-
type: A<int>
156+
type: A<dynamic>
156157
period: .
157158
name: SimpleIdentifier
158159
token: named
@@ -165,7 +166,7 @@ InstanceCreationExpression
165166
staticElement: ConstructorMember
166167
base: <testLibrary>::@fragment::package:test/a.dart::@classAugmentation::A::@constructor::named
167168
augmentationSubstitution: {T2: T}
168-
substitution: {T: int}
169+
substitution: {T: dynamic}
169170
element: <testLibrary>::@fragment::package:test/a.dart::@classAugmentation::A::@constructor::named#element
170171
argumentList: ArgumentList
171172
leftParenthesis: (
@@ -175,10 +176,10 @@ InstanceCreationExpression
175176
parameter: ParameterMember
176177
base: <testLibrary>::@fragment::package:test/a.dart::@classAugmentation::A::@constructor::named::@parameter::value
177178
augmentationSubstitution: {T2: T}
178-
substitution: {T: int}
179+
substitution: {T: dynamic}
179180
staticType: int
180181
rightParenthesis: )
181-
staticType: A<int>
182+
staticType: A<dynamic>
182183
''');
183184
}
184185

@@ -1359,6 +1360,7 @@ void f() {
13591360
''');
13601361

13611362
var node = findNode.singleInstanceCreationExpression;
1363+
// TODO(scheglov): should be `A<int>`
13621364
assertResolvedNodeText(node, r'''
13631365
InstanceCreationExpression
13641366
constructorName: ConstructorName
@@ -1371,7 +1373,7 @@ InstanceCreationExpression
13711373
name: A
13721374
element: package:test/a.dart::<fragment>::@class::A
13731375
element2: package:test/a.dart::@class::A
1374-
type: A<int>
1376+
type: A<dynamic>
13751377
period: .
13761378
name: SimpleIdentifier
13771379
token: named
@@ -1384,7 +1386,7 @@ InstanceCreationExpression
13841386
staticElement: ConstructorMember
13851387
base: package:test/a.dart::@fragment::package:test/b.dart::@classAugmentation::A::@constructor::named
13861388
augmentationSubstitution: {T2: T}
1387-
substitution: {T: int}
1389+
substitution: {T: dynamic}
13881390
element: package:test/a.dart::@fragment::package:test/b.dart::@classAugmentation::A::@constructor::named#element
13891391
argumentList: ArgumentList
13901392
leftParenthesis: (
@@ -1394,10 +1396,10 @@ InstanceCreationExpression
13941396
parameter: ParameterMember
13951397
base: package:test/a.dart::@fragment::package:test/b.dart::@classAugmentation::A::@constructor::named::@parameter::value
13961398
augmentationSubstitution: {T2: T}
1397-
substitution: {T: int}
1399+
substitution: {T: dynamic}
13981400
staticType: int
13991401
rightParenthesis: )
1400-
staticType: A<int>
1402+
staticType: A<dynamic>
14011403
''');
14021404
}
14031405

0 commit comments

Comments
 (0)