Skip to content

Commit cbf9cff

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Infer types of field formals before all fields.
It will not happen strictly before, it happens together, because we set _FunctionElementForLink_Initializer for fields, which will perform field type inference when requested. Found this while running over google3. R=brianwilkerson@google.com, paulberry@google.com Change-Id: I360dff7e815ba997680c4a719a3e82827368db42 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107780 Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 0c6b3d1 commit cbf9cff

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

pkg/analyzer/lib/src/summary2/top_level_inference.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class TopLevelInference {
9393
initializerInference.createNodes();
9494

9595
_performOverrideInference();
96-
initializerInference.perform();
9796
_inferConstructorFieldFormals();
97+
initializerInference.perform();
9898
}
9999

100100
void _inferConstructorFieldFormals() {
@@ -103,6 +103,7 @@ class TopLevelInference {
103103
for (var class_ in unit.types) {
104104
var fields = <String, DartType>{};
105105
for (var field in class_.fields) {
106+
if (field.isStatic) continue;
106107
if (field.isSynthetic) continue;
107108

108109
var name = field.name;

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9580,6 +9580,21 @@ int y;
95809580
''');
95819581
}
95829582

9583+
test_type_inference_fieldFormal_depends_onField() async {
9584+
var library = await checkLibrary('''
9585+
class A<T> {
9586+
var f = 0;
9587+
A(this.f);
9588+
}
9589+
''');
9590+
checkElementText(library, r'''
9591+
class A<T> {
9592+
int f;
9593+
A(int this.f);
9594+
}
9595+
''');
9596+
}
9597+
95839598
test_type_inference_multiplyDefinedElement() async {
95849599
addLibrarySource('/a.dart', 'class C {}');
95859600
addLibrarySource('/b.dart', 'class C {}');
@@ -9622,6 +9637,34 @@ dynamic Function([dynamic]) x;
96229637
''');
96239638
}
96249639

9640+
test_type_inference_topVariable_depends_onFieldFormal() async {
9641+
var library = await checkLibrary('''
9642+
class A {}
9643+
9644+
class B extends A {}
9645+
9646+
class C<T extends A> {
9647+
final T f;
9648+
const C(this.f);
9649+
}
9650+
9651+
final b = B();
9652+
final c = C(b);
9653+
''');
9654+
checkElementText(library, r'''
9655+
class A {
9656+
}
9657+
class B extends A {
9658+
}
9659+
class C<T extends A> {
9660+
final T f;
9661+
const C(T this.f);
9662+
}
9663+
final B b;
9664+
final C<B> c;
9665+
''');
9666+
}
9667+
96259668
test_type_invalid_topLevelVariableElement_asType() async {
96269669
var library = await checkLibrary('''
96279670
class C<T extends V> {}

0 commit comments

Comments
 (0)