[Flow analysis] Remove unnecessary `staticType` arguments from API.

The flow analysis methods `thisOrSuper` and
`whyNotPromotedImplicitThis` no longer need the caller to provide the
`staticType` of `this`, since flow analysis knows the type of `this`
at every point in program execution.

Change-Id: I19ced27bdc5fec964fce6f930fccc8ff6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/550841
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart b/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
index b1140c8..04dd786 100644
--- a/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
+++ b/pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
@@ -1745,8 +1745,6 @@
   /// pseudo-expression `super`, in the case of the analyzer, which represents
   /// `super.x` as a property get whose target is `super`).
   ///
-  /// [staticType] should be the static type of `this`.
-  ///
   /// [isSuper] indicates whether the expression that was visited was the
   /// pseudo-expression `super`.
   ///
@@ -1754,10 +1752,7 @@
   ///
   /// `null` is returned in the event that there is no binding for `this` (which
   /// should only happen in error recovery scenarios).
-  ExpressionInfo? thisOrSuper(
-    SharedTypeView staticType, {
-    required bool isSuper,
-  });
+  ExpressionInfo? thisOrSuper({required bool isSuper});
 
   /// Call this method just before visiting the body of a "try/catch" statement.
   ///
@@ -1964,8 +1959,6 @@
   /// promotion, to retrieve information about why an implicit reference to
   /// `this` was not promoted.
   ///
-  /// [staticType] is the (unpromoted) type of `this`.
-  ///
   /// The returned value is a function yielding a map whose keys are types that
   /// the user might have been expecting `this` to be promoted to, and whose
   /// values are reasons why the corresponding promotion did not occur. The
@@ -1986,9 +1979,8 @@
   /// freely call this method after any expression for which an error *might*
   /// need to be generated, and then defer invoking the returned function until
   /// it is determined that an error actually occurred.
-  Map<SharedTypeView, NonPromotionReason> Function() whyNotPromotedImplicitThis(
-    SharedTypeView staticType,
-  );
+  Map<SharedTypeView, NonPromotionReason> Function()
+  whyNotPromotedImplicitThis();
 
   /// Registers a write of the given [variable] in the current state.
   ///
@@ -3343,13 +3335,10 @@
   }
 
   @override
-  ExpressionInfo? thisOrSuper(
-    SharedTypeView staticType, {
-    required bool isSuper,
-  }) {
+  ExpressionInfo? thisOrSuper({required bool isSuper}) {
     return _wrap(
-      'thisOrSuper($staticType, isSuper: $isSuper)',
-      () => _wrapped.thisOrSuper(staticType, isSuper: isSuper),
+      'thisOrSuper(isSuper: $isSuper)',
+      () => _wrapped.thisOrSuper(isSuper: isSuper),
       isQuery: true,
       isPure: false,
     );
@@ -3495,13 +3484,11 @@
   }
 
   @override
-  Map<SharedTypeView, NonPromotionReason> Function() whyNotPromotedImplicitThis(
-    SharedTypeView staticType,
-  ) {
+  Map<SharedTypeView, NonPromotionReason> Function()
+  whyNotPromotedImplicitThis() {
     return _wrap(
-      'whyNotPromotedImplicitThis($staticType)',
-      () =>
-          _trackWhyNotPromoted(_wrapped.whyNotPromotedImplicitThis(staticType)),
+      'whyNotPromotedImplicitThis()',
+      () => _trackWhyNotPromoted(_wrapped.whyNotPromotedImplicitThis()),
       isQuery: true,
     );
   }
@@ -7833,11 +7820,8 @@
   }
 
   @override
-  ExpressionInfo? thisOrSuper(
-    SharedTypeView staticType, {
-    required bool isSuper,
-  }) {
-    return _thisOrSuperReference(staticType, isSuper: isSuper);
+  ExpressionInfo? thisOrSuper({required bool isSuper}) {
+    return _thisOrSuperReference(isSuper: isSuper);
   }
 
   @override
@@ -8059,13 +8043,12 @@
   }
 
   @override
-  Map<SharedTypeView, NonPromotionReason> Function() whyNotPromotedImplicitThis(
-    SharedTypeView staticType,
-  ) {
+  Map<SharedTypeView, NonPromotionReason> Function()
+  whyNotPromotedImplicitThis() {
     if (typeAnalyzerOptions.thisPromotionEnabled) {
       return () => {};
     }
-    _Reference? reference = _thisOrSuperReference(staticType, isSuper: false);
+    _Reference? reference = _thisOrSuperReference(isSuper: false);
     if (reference == null) return () => {};
     PromotionModel? currentThisInfo = _current.promotionInfo?.get(
       this,
@@ -9071,23 +9054,12 @@
     _logBuilder?.promotionInfoChanged(value.promotionInfo, offset: offset);
   }
 
-  _Reference? _thisOrSuperReference(
-    SharedTypeView staticType, {
-    required bool isSuper,
-  }) {
-    assert(() {
-      SharedTypeView expectedType =
-          (isSuper
-              ? _unpromotedThisTypes.lastOrNull
-              : promotedTypeOfThis ?? _unpromotedThisTypes.lastOrNull) ??
-          operations.errorType;
-      assert(
-        staticType == expectedType,
-        'Incorrect `this` or `super` type. Got $staticType, expected '
-        '$expectedType.',
-      );
-      return true;
-    }());
+  _Reference? _thisOrSuperReference({required bool isSuper}) {
+    SharedTypeView staticType =
+        (isSuper
+            ? _unpromotedThisTypes.lastOrNull
+            : promotedTypeOfThis ?? _unpromotedThisTypes.lastOrNull) ??
+        operations.errorType;
     SsaNode ssaNode = isSuper ? _superSsaNode : _thisSsaNode;
     PromotionKey? promotionKey = _thisPromotionKeys.lastOrNull;
     if (promotionKey == null) return null;
diff --git a/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_mini_ast.dart b/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_mini_ast.dart
index 7116484..446bfed 100644
--- a/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_mini_ast.dart
+++ b/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_mini_ast.dart
@@ -20,13 +20,8 @@
     new _GetSsaNodes(callback, location: computeLocation());
 
 Expression implicitThis_whyNotPromoted(
-  String staticType,
   void Function(Map<SharedTypeView, NonPromotionReason>) callback,
-) => new _WhyNotPromoted_ImplicitThis(
-  Type(staticType),
-  callback,
-  location: computeLocation(),
-);
+) => new _WhyNotPromoted_ImplicitThis(callback, location: computeLocation());
 
 /// Test harness for creating flow analysis tests.  This class provides all
 /// the [FlowAnalysisOperations] needed by flow analysis, as well as other
@@ -147,15 +142,9 @@
 }
 
 class _WhyNotPromoted_ImplicitThis extends Expression {
-  final Type staticType;
-
   final void Function(Map<SharedTypeView, NonPromotionReason>) callback;
 
-  _WhyNotPromoted_ImplicitThis(
-    this.staticType,
-    this.callback, {
-    required super.location,
-  });
+  _WhyNotPromoted_ImplicitThis(this.callback, {required super.location});
 
   @override
   void preVisitInternal(PreVisitor visitor) {}
@@ -165,7 +154,7 @@
 
   @override
   ExpressionTypeAnalysisResult visit(Harness h, SharedTypeSchemaView schema) {
-    callback(h.flow.whyNotPromotedImplicitThis(SharedTypeView(staticType))());
+    callback(h.flow.whyNotPromotedImplicitThis()());
     h.irBuilder.atom('noop', Kind.expression, location: location);
     return ExpressionTypeAnalysisResult(
       type: SharedTypeView(h.typeAnalyzer.nullType),
diff --git a/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart b/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart
index 27c190d..4dbb353 100644
--- a/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart
+++ b/pkg/_fe_analyzer_shared/test/flow_analysis/flow_analysis_test.dart
@@ -5719,7 +5719,7 @@
         h.addSuperInterfaces('C', (_) => [Type('Object')]);
         h.run([
           if_(this_.isNot('D'), [return_()]),
-          implicitThis_whyNotPromoted('C', (reasons) {
+          implicitThis_whyNotPromoted((reasons) {
             expect(reasons.keys, unorderedEquals([Type('D')]));
             var nonPromotionReason = reasons.values.single as ThisNotPromoted;
             expect(
@@ -5752,7 +5752,7 @@
         h.addSuperInterfaces('C', (_) => [Type('Object')]);
         h.run([
           if_(this_.isNot('D'), [return_()]),
-          implicitThis_whyNotPromoted('C', (reasons) {
+          implicitThis_whyNotPromoted((reasons) {
             expect(reasons, isEmpty);
           }),
         ]);
diff --git a/pkg/_fe_analyzer_shared/test/mini_ast.dart b/pkg/_fe_analyzer_shared/test/mini_ast.dart
index 4703706..bf92bb8 100644
--- a/pkg/_fe_analyzer_shared/test/mini_ast.dart
+++ b/pkg/_fe_analyzer_shared/test/mini_ast.dart
@@ -7667,10 +7667,7 @@
   ExpressionTypeAnalysisResult analyzeThis(Expression node) {
     var promotedTypeOfThis = flow.promotedTypeOfThis?.unwrapTypeView() as Type?;
     var thisType = promotedTypeOfThis ?? this.thisType;
-    var flowAnalysisInfo = flow.thisOrSuper(
-      SharedTypeView(thisType),
-      isSuper: false,
-    );
+    var flowAnalysisInfo = flow.thisOrSuper(isSuper: false);
     return new ExpressionTypeAnalysisResult(
       type: SharedTypeView(thisType),
       flowAnalysisInfo: flowAnalysisInfo,
diff --git a/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart
index 5201b1a..6d4930e 100644
--- a/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/type_property_resolver.dart
@@ -2,7 +2,6 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
-import 'package:_fe_analyzer_shared/src/types/shared_type.dart';
 import 'package:analyzer/dart/ast/syntactic_entity.dart';
 import 'package:analyzer/dart/element/element.dart';
 import 'package:analyzer/dart/element/nullability_suffix.dart';
@@ -169,7 +168,7 @@
           if (thisType != null) {
             messages = _resolver.computeWhyNotPromotedMessages(
               nameErrorEntity,
-              flow.whyNotPromotedImplicitThis(SharedTypeView(thisType))(),
+              flow.whyNotPromotedImplicitThis()(),
             );
           }
         }
diff --git a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
index 086b8b8..3aee9ab 100644
--- a/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
+++ b/pkg/analyzer/lib/src/generated/static_type_analyzer.dart
@@ -249,10 +249,7 @@
     } else {
       _resolver.flowAnalysis.storeExpressionInfo(
         node,
-        _resolver.flowAnalysis.flow?.thisOrSuper(
-          SharedTypeView(thisType),
-          isSuper: true,
-        ),
+        _resolver.flowAnalysis.flow?.thisOrSuper(isSuper: true),
       );
     }
     node.recordStaticType(thisType, resolver: _resolver);
@@ -270,10 +267,7 @@
         InvalidTypeImpl.instance;
     _resolver.flowAnalysis.storeExpressionInfo(
       node,
-      _resolver.flowAnalysis.flow?.thisOrSuper(
-        SharedTypeView(staticType),
-        isSuper: false,
-      ),
+      _resolver.flowAnalysis.flow?.thisOrSuper(isSuper: false),
     );
     node.recordStaticType(staticType, resolver: _resolver);
   }
diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor.dart b/pkg/front_end/lib/src/type_inference/inference_visitor.dart
index 1cad7bf..18cb897 100644
--- a/pkg/front_end/lib/src/type_inference/inference_visitor.dart
+++ b/pkg/front_end/lib/src/type_inference/inference_visitor.dart
@@ -10508,7 +10508,7 @@
     }
     storeExpressionInfo(
       loweredExpression,
-      flowAnalysis.thisOrSuper(new SharedTypeView(thisType), isSuper: false),
+      flowAnalysis.thisOrSuper(isSuper: false),
     );
     return new ExpressionInferenceResult(thisType, loweredExpression);
   }
diff --git a/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart b/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart
index 3f55f4c..4fdc596 100644
--- a/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart
+++ b/pkg/front_end/lib/src/type_inference/inference_visitor_base.dart
@@ -4376,10 +4376,7 @@
                   // Coverage-ignore(suite): Not run.
                   ?.unwrapTypeView()
               as DartType?;
-      expressionInfo = flowAnalysis.thisOrSuper(
-        new SharedTypeView(promotedType ?? variable.type),
-        isSuper: false,
-      );
+      expressionInfo = flowAnalysis.thisOrSuper(isSuper: false);
     } else if (variable is! InternalLocalFunctionVariable) {
       // Don't promote local functions.
       SharedTypeView? wrappedPromotedType;