Clean up uses of DartType.flattenFutures

Change-Id: I21a950f8be4035a1aacda0c46b64754d22dc60f6
Reviewed-on: https://dart-review.googlesource.com/c/87610
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 5ca19f8..bff4d6b 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -1737,9 +1737,8 @@
     if (_inGenerator) {
       return;
     }
-    var returnType = _inAsync
-        ? expectedReturnType.flattenFutures(_typeSystem)
-        : expectedReturnType;
+    var returnType =
+        _inAsync ? _typeSystem.flatten(expectedReturnType) : expectedReturnType;
     if (returnType.isDynamic ||
         returnType.isDartCoreNull ||
         returnType.isVoid) {
@@ -5025,8 +5024,8 @@
     var toType = expectedType;
     var fromType = expressionType;
     if (_inAsync) {
-      toType = toType.flattenFutures(_typeSystem);
-      fromType = fromType.flattenFutures(_typeSystem);
+      toType = _typeSystem.flatten(toType);
+      fromType = _typeSystem.flatten(fromType);
     }
 
     // Anything can be returned to `void` in an arrow bodied function
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index b7853c6..6b3fcec 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -958,9 +958,8 @@
         return;
       }
 
-      var flattenedType = body.isAsynchronous
-          ? returnType.flattenFutures(_typeSystem)
-          : returnType;
+      var flattenedType =
+          body.isAsynchronous ? _typeSystem.flatten(returnType) : returnType;
 
       // dynamic/Null/void are allowed to omit a return.
       if (flattenedType.isDynamic ||
@@ -4799,7 +4798,7 @@
 
       DartType type = node.expression.staticType;
       if (_enclosingFunction.isAsynchronous) {
-        type = type.flattenFutures(typeSystem);
+        type = typeSystem.flatten(type);
       }
       if (type != null) {
         inferenceContext.addReturnOrYieldType(type);
@@ -5299,7 +5298,7 @@
     // we're processing erroneous code.
     if (type != null && _enclosingFunction?.isGenerator == false) {
       if (_enclosingFunction.isAsynchronous) {
-        type = type.flattenFutures(typeSystem);
+        type = typeSystem.flatten(type);
       }
       inferenceContext.addReturnOrYieldType(type);
     }
@@ -5551,7 +5550,7 @@
         }
       }
       // async functions expect `Future<T> | T`
-      var futureTypeParam = declaredType.flattenFutures(typeSystem);
+      var futureTypeParam = typeSystem.flatten(declaredType);
       return _createFutureOr(futureTypeParam);
     }
     return declaredType;
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 2bd4836..89dbcb5 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -362,7 +362,7 @@
       if (awaitedType.isDartAsyncFutureOr) {
         return awaitType((awaitedType as InterfaceType).typeArguments[0]);
       }
-      return awaitedType.flattenFutures(_typeSystem);
+      return _typeSystem.flatten(awaitedType);
     }
 
     _recordStaticType(node, awaitType(_getStaticType(node.expression)));
@@ -1238,7 +1238,7 @@
         type = (type as InterfaceType).typeArguments[0];
       }
       return _typeProvider.futureType
-          .instantiate(<DartType>[type.flattenFutures(_typeSystem)]);
+          .instantiate(<DartType>[_typeSystem.flatten(type)]);
     } else {
       return type;
     }
diff --git a/pkg/analyzer/lib/src/summary/link.dart b/pkg/analyzer/lib/src/summary/link.dart
index 6cd8179..0507d99 100644
--- a/pkg/analyzer/lib/src/summary/link.dart
+++ b/pkg/analyzer/lib/src/summary/link.dart
@@ -5299,7 +5299,7 @@
             bodyType = (bodyType as InterfaceType).typeArguments[0];
           }
           bodyType = typeProvider.futureType
-              .instantiate([bodyType.flattenFutures(typeSystem)]);
+              .instantiate([typeSystem.flatten(bodyType)]);
         }
         functionElement._setInferredType(bodyType);
       }
diff --git a/pkg/analyzer/test/generated/static_type_analyzer_test.dart b/pkg/analyzer/test/generated/static_type_analyzer_test.dart
index 3d40fdc..e0c2bc9 100644
--- a/pkg/analyzer/test/generated/static_type_analyzer_test.dart
+++ b/pkg/analyzer/test/generated/static_type_analyzer_test.dart
@@ -1535,7 +1535,7 @@
     return _visitor.typeAnalyzer;
   }
 
-  DartType _flatten(DartType type) => type.flattenFutures(_typeSystem);
+  DartType _flatten(DartType type) => _typeSystem.flatten(type);
 
   /**
    * Return a boolean literal with the given [value] that has been resolved to