Fix cases where TypeImpl.toString() is used.

Instead getDisplayString() should be used.

Change-Id: I1c988bc9d193398aadbb32620e01f11ea3e353d4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213900
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 3049ed4..cc2ed46 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -580,8 +580,12 @@
                   computeMemberId(whyNotPromotedVisitor.propertyReference!);
               args.add('target: $id');
             }
-            if (whyNotPromotedVisitor.propertyType != null) {
-              args.add('type: ${whyNotPromotedVisitor.propertyType}');
+            var propertyType = whyNotPromotedVisitor.propertyType;
+            if (propertyType != null) {
+              var propertyTypeStr = propertyType.getDisplayString(
+                withNullability: true,
+              );
+              args.add('type: $propertyTypeStr');
             }
             if (args.isNotEmpty) {
               nonPromotionReasonText += '(${args.join(', ')})';
diff --git a/pkg/analyzer/test/src/summary/resolved_ast_printer.dart b/pkg/analyzer/test/src/summary/resolved_ast_printer.dart
index 9b9051e..1921da7 100644
--- a/pkg/analyzer/test/src/summary/resolved_ast_printer.dart
+++ b/pkg/analyzer/test/src/summary/resolved_ast_printer.dart
@@ -1809,6 +1809,7 @@
     return '{$entriesStr}';
   }
 
+  /// TODO(scheglov) Make [type] non-nullable?
   String? _typeStr(DartType? type) {
     return type?.getDisplayString(withNullability: _withNullability);
   }
@@ -1989,7 +1990,8 @@
       _writelnWithIndent(name);
       _withIndent(() {
         for (var type in types) {
-          _writelnWithIndent('$type');
+          var typeStr = _typeStr(type);
+          _writelnWithIndent('$typeStr');
         }
       });
     }
diff --git a/pkg/analyzer/test/src/summary/resynthesize_common.dart b/pkg/analyzer/test/src/summary/resynthesize_common.dart
index 685f2f4..487ad9e 100644
--- a/pkg/analyzer/test/src/summary/resynthesize_common.dart
+++ b/pkg/analyzer/test/src/summary/resynthesize_common.dart
@@ -33836,7 +33836,7 @@
     expect(variable, isNotNull);
     expect(variable.isFinal, isFalse);
     expect(variable.getter, same(getter));
-    expect('${variable.type}', 'int');
+    _assertTypeStr(variable.type, 'int');
     expect(variable, same(_elementOfDefiningUnit(library, ['@variable', 'x'])));
   }