Issue 33930. Fix resynthesizing function typed field formal parameter types.
R=brianwilkerson@google.com, paulberry@google.com
Bug: https://github.com/dart-lang/sdk/issues/33930
Change-Id: I81c14cf5edf67eaeb253daefce3b91f0002b36a2
Reviewed-on: https://dart-review.googlesource.com/c/89440
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index 65a6d01..f764d36 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -4206,7 +4206,10 @@
@override
DartType get type {
- if (unlinkedParam != null && unlinkedParam.type == null && field != null) {
+ if (unlinkedParam != null &&
+ unlinkedParam.type == null &&
+ !unlinkedParam.isFunctionTyped &&
+ field != null) {
_type ??= field?.type ?? DynamicTypeImpl.instance;
}
return super.type;
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 9267132..69d2215 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -451,6 +451,36 @@
''');
}
+ test_class_constructor_field_formal_functionTyped_noReturnType() async {
+ var library = await checkLibrary(r'''
+class C {
+ var x;
+ C(this.x(double b));
+}
+''');
+ checkElementText(library, r'''
+class C {
+ dynamic x;
+ C((double) → dynamic this.x);
+}
+''');
+ }
+
+ test_class_constructor_field_formal_functionTyped_withReturnType() async {
+ var library = await checkLibrary(r'''
+class C {
+ var x;
+ C(int this.x(double b));
+}
+''');
+ checkElementText(library, r'''
+class C {
+ dynamic x;
+ C((double) → int this.x);
+}
+''');
+ }
+
test_class_constructor_field_formal_multiple_matching_fields() async {
// This is a compile-time error but it should still analyze consistently.
var library = await checkLibrary('class C { C(this.x); int x; String x; }',