Infer types of fields from initializers.
R=brianwilkerson@google.com
Change-Id: I4c76ec22802e226f51eef1235463221b35532f9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/97741
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/top_level_inference.dart b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
index 5d7f97a..bc73af6 100644
--- a/pkg/analyzer/lib/src/summary2/top_level_inference.dart
+++ b/pkg/analyzer/lib/src/summary2/top_level_inference.dart
@@ -82,12 +82,11 @@
for (LinkedNodeBuilder unitDeclaration in unitDeclarations) {
if (unitDeclaration.kind == LinkedNodeKind.classDeclaration) {
_visitClassFields(unitDeclaration, (field) {
- var name = unit.context.getVariableName(field);
+// var name = unit.context.getVariableName(field);
// TODO(scheglov) Use inheritance
+ // TODO(scheglov) infer in the correct order
if (field.variableDeclaration_type2 == null) {
- field.variableDeclaration_type2 = LinkedNodeTypeBuilder(
- kind: LinkedNodeTypeKind.dynamic_,
- );
+ _inferVariableTypeFromInitializerTemporary(field);
}
});
diff --git a/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart b/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
index 0642144..18c6287 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_ast2_test.dart
@@ -230,23 +230,12 @@
@override
@failingTest
test_const_finalField_hasConstConstructor() async {
+ // TODO(scheglov) Needs initializer, because of const constructor.
await super.test_const_finalField_hasConstConstructor();
}
@override
@failingTest
- test_const_invalid_field_const() async {
- await super.test_const_invalid_field_const();
- }
-
- @override
- @failingTest
- test_const_invalid_field_final() async {
- await super.test_const_invalid_field_final();
- }
-
- @override
- @failingTest
test_const_invokeConstructor_generic_named_imported_withPrefix() async {
await super
.test_const_invokeConstructor_generic_named_imported_withPrefix();
@@ -364,12 +353,6 @@
@override
@failingTest
- test_const_reference_type_functionType() async {
- await super.test_const_reference_type_functionType();
- }
-
- @override
- @failingTest
test_const_reference_type_imported_withPrefix() async {
await super.test_const_reference_type_imported_withPrefix();
}
@@ -677,30 +660,12 @@
@override
@failingTest
- test_field_inferred_type_nonStatic_implicit_initialized() async {
- await super.test_field_inferred_type_nonStatic_implicit_initialized();
- }
-
- @override
- @failingTest
test_field_inferred_type_nonStatic_implicit_uninitialized() async {
await super.test_field_inferred_type_nonStatic_implicit_uninitialized();
}
@override
@failingTest
- test_field_inferred_type_static_implicit_initialized() async {
- await super.test_field_inferred_type_static_implicit_initialized();
- }
-
- @override
- @failingTest
- test_field_propagatedType_const_noDep() async {
- await super.test_field_propagatedType_const_noDep();
- }
-
- @override
- @failingTest
test_field_propagatedType_final_dep_inLib() async {
await super.test_field_propagatedType_final_dep_inLib();
}
@@ -713,30 +678,6 @@
@override
@failingTest
- test_field_propagatedType_final_noDep_instance() async {
- await super.test_field_propagatedType_final_noDep_instance();
- }
-
- @override
- @failingTest
- test_field_propagatedType_final_noDep_static() async {
- await super.test_field_propagatedType_final_noDep_static();
- }
-
- @override
- @failingTest
- test_field_static_final_untyped() async {
- await super.test_field_static_final_untyped();
- }
-
- @override
- @failingTest
- test_field_untyped() async {
- await super.test_field_untyped();
- }
-
- @override
- @failingTest
test_function_entry_point_in_export_hidden() async {
await super.test_function_entry_point_in_export_hidden();
}
@@ -949,13 +890,6 @@
@override
@failingTest
- test_initializer_executable_with_return_type_from_closure_field() async {
- await super
- .test_initializer_executable_with_return_type_from_closure_field();
- }
-
- @override
- @failingTest
test_instantiateToBounds_boundRefersToEarlierTypeArgument() async {
await super.test_instantiateToBounds_boundRefersToEarlierTypeArgument();
}