Enhance change-type-annotation to support record types
Change-Id: Ib5bbdec16c88858cda4f1739ad92a4c68e598a6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262261
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/change_type_annotation.dart b/pkg/analysis_server/lib/src/services/correction/dart/change_type_annotation.dart
index a84c667..6add26a 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/change_type_annotation.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/change_type_annotation.dart
@@ -40,7 +40,9 @@
var typeNode = variableList.type;
if (typeNode != null) {
var newType = initializer.typeOrThrow;
- if (newType is InterfaceType || newType is FunctionType) {
+ if (newType is InterfaceType ||
+ newType is FunctionType ||
+ newType is RecordType) {
_oldAnnotation = displayStringForType(typeNode.typeOrThrow);
_newAnnotation = displayStringForType(newType);
await builder.addDartFileEdit(file, (builder) {
diff --git a/pkg/analysis_server/test/src/services/correction/fix/change_type_annotation_test.dart b/pkg/analysis_server/test/src/services/correction/fix/change_type_annotation_test.dart
index 9db4307..429deba 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/change_type_annotation_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/change_type_annotation_test.dart
@@ -75,6 +75,36 @@
await assertNoFix();
}
+ Future<void> test_recordType_from() async {
+ await resolveTestCode(r'''
+f() {
+ (String, String) v = ('a', 'b').$0;
+ print(v);
+}
+''');
+ await assertHasFix(r'''
+f() {
+ String v = ('a', 'b').$0;
+ print(v);
+}
+''');
+ }
+
+ Future<void> test_recordType_to() async {
+ await resolveTestCode('''
+f() {
+ String v = ('a', 'b');
+ print(v);
+}
+''');
+ await assertHasFix('''
+f() {
+ (String, String) v = ('a', 'b');
+ print(v);
+}
+''');
+ }
+
Future<void> test_simple() async {
await resolveTestCode('''
f() {