[dart2wasm] Fix bug in algorithm to reuse super `_typeArguments`.

language/type_variable/promotion_test starts failing because
`joinReplaceAllResult` isn't implemented yet.

Change-Id: Ifd7ff6d94486499b8cf398dd2c749d10500e242a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250480
Commit-Queue: Joshua Litt <joshualitt@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
diff --git a/pkg/dart2wasm/lib/transformers.dart b/pkg/dart2wasm/lib/transformers.dart
index 3351fa7..fe9d23e 100644
--- a/pkg/dart2wasm/lib/transformers.dart
+++ b/pkg/dart2wasm/lib/transformers.dart
@@ -51,10 +51,25 @@
     return result;
   }
 
-  /// We can reuse a superclass' `_typeArguments` method if the subclass and the
-  /// superclass have the exact same type parameters in the exact same order.
+  /// Checks to see if it is safe to reuse `super._typeArguments`.
   bool canReuseSuperMethod(Class cls) {
-    Supertype supertype = cls.supertype!;
+    // We search for the first non-abstract super in [cls]'s inheritance chain
+    // to see if we can reuse its `_typeArguments` method.
+    Class classIter = cls;
+    late Supertype supertype;
+    while (classIter.supertype != null) {
+      Supertype supertypeIter = classIter.supertype!;
+      Class superclass = supertypeIter.classNode;
+      if (!superclass.isAbstract) {
+        supertype = supertypeIter;
+        break;
+      }
+      classIter = classIter.supertype!.classNode;
+    }
+
+    // We can reuse a superclass' `_typeArguments` method if the subclass and
+    // the superclass have the exact same type parameters in the exact same
+    // order.
     if (cls.typeParameters.length != supertype.typeArguments.length) {
       return false;
     }