Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cea39db

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Perform instance member inference for mixins.
The set of sets is not comprehensive, no tests for fields and accessors. [email protected] Change-Id: I105ed6b1d4b5836f61af9f8abe7fed7e7a6b8c59 Reviewed-on: https://dart-review.googlesource.com/74941 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 65b390c commit cea39db

File tree

11 files changed

+657
-469
lines changed

11 files changed

+657
-469
lines changed

pkg/analyzer/lib/src/summary/link.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,9 @@ class CompilationUnitElementInBuildUnit extends CompilationUnitElementForLink {
15551555
for (ClassElementForLink classElement in types) {
15561556
classElement.link(this);
15571557
}
1558+
for (ClassElementForLink classElement in mixins) {
1559+
classElement.link(this);
1560+
}
15581561
}
15591562

15601563
/// Throw away any information stored in the summary by a previous call to

pkg/analyzer/lib/src/task/strong_mode.dart

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,8 @@ class InstanceMemberInferrer {
7878
* compilation [unit].
7979
*/
8080
void inferCompilationUnit(CompilationUnitElement unit) {
81-
for (ClassElement classElement in unit.types) {
82-
try {
83-
_inferClass(classElement);
84-
} on _CycleException {
85-
// This is a short circuit return to prevent types that inherit from
86-
// types containing a circular reference from being inferred.
87-
}
88-
}
81+
_inferClasses(unit.mixins);
82+
_inferClasses(unit.types);
8983
}
9084

9185
/**
@@ -306,6 +300,7 @@ class InstanceMemberInferrer {
306300
_inferType(classElement.supertype);
307301
classElement.mixins.forEach(_inferType);
308302
classElement.interfaces.forEach(_inferType);
303+
classElement.superclassConstraints.forEach(_inferType);
309304
//
310305
// Then infer the types for the members.
311306
//
@@ -330,6 +325,17 @@ class InstanceMemberInferrer {
330325
}
331326
}
332327

328+
void _inferClasses(List<ClassElement> elements) {
329+
for (ClassElement element in elements) {
330+
try {
331+
_inferClass(element);
332+
} on _CycleException {
333+
// This is a short circuit return to prevent types that inherit from
334+
// types containing a circular reference from being inferred.
335+
}
336+
}
337+
}
338+
333339
void _inferConstructorFieldFormals(ConstructorElement constructor) {
334340
for (ParameterElement parameter in constructor.parameters) {
335341
if (parameter.hasImplicitType &&

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ abstract class B extends A {
7070
''');
7171
await resolveTestFile();
7272
assertTestErrors([CompileTimeErrorCode.ABSTRACT_SUPER_MEMBER_REFERENCE]);
73-
assertElement(findNode.simple('foo(); // ref'), findElement.method('foo'));
73+
assertElement(
74+
findNode.simple('foo(); // ref'),
75+
findElement.method('foo', of: 'A'),
76+
);
7477
}
7578

7679
test_abstractSuperMemberReference_method_reference() async {
@@ -110,7 +113,7 @@ class C extends B {
110113
assertNoTestErrors();
111114
assertElement(
112115
findNode.simple('foo(); // ref'),
113-
findElement.method('foo', className: 'M'),
116+
findElement.method('foo', of: 'M'),
114117
);
115118
}
116119

@@ -137,7 +140,7 @@ class C extends A with B {
137140
assertNoTestErrors();
138141
assertElement(
139142
findNode.simple('foo(); // ref'),
140-
findElement.method('foo', className: 'B'),
143+
findElement.method('foo', of: 'B'),
141144
);
142145
}
143146

@@ -161,7 +164,7 @@ class C extends A with B {
161164
assertNoTestErrors();
162165
assertElement(
163166
findNode.simple('foo(); // ref'),
164-
findElement.method('foo', className: 'A'),
167+
findElement.method('foo', of: 'A'),
165168
);
166169
}
167170

@@ -207,7 +210,7 @@ class C extends B {
207210
assertNoTestErrors();
208211
assertElement(
209212
findNode.simple('foo(); // ref'),
210-
findElement.method('foo', className: 'A'),
213+
findElement.method('foo', of: 'A'),
211214
);
212215
}
213216

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,16 +149,36 @@ class FindElement {
149149
return result;
150150
}
151151

152-
MethodElement method(String name, {String className}) {
152+
MethodElement method(String name, {String of}) {
153+
MethodElement result;
154+
155+
void findIn(List<MethodElement> methods) {
156+
for (var method in methods) {
157+
if (method.name == name) {
158+
if (result != null) {
159+
throw new StateError('Method name $name is not unique.');
160+
}
161+
result = method;
162+
}
163+
}
164+
}
165+
153166
for (var class_ in unitElement.types) {
154-
if (className != null && class_.name != className) {
167+
if (of != null && class_.name != of) {
155168
continue;
156169
}
157-
for (var method in class_.methods) {
158-
if (method.name == name) {
159-
return method;
160-
}
170+
findIn(class_.methods);
171+
}
172+
173+
for (var mixin in unitElement.mixins) {
174+
if (of != null && mixin.name != of) {
175+
continue;
161176
}
177+
findIn(mixin.methods);
178+
}
179+
180+
if (result != null) {
181+
return result;
162182
}
163183
fail('Not found class method: $name');
164184
}

0 commit comments

Comments
 (0)