Prevent infinite recursion via not 'self'.

When we are checking `A`, we will catch self-reference and stop.
But when we are checking `B`, we still need to stop.

typedef A A();
typedef B(A a);

R=brianwilkerson@google.com

Change-Id: I8ad57a94301ec3379c2480c782637c502aa02675
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/101464
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/lib/src/summary2/type_alias.dart b/pkg/analyzer/lib/src/summary2/type_alias.dart
index 56ed006..cc1830b 100644
--- a/pkg/analyzer/lib/src/summary2/type_alias.dart
+++ b/pkg/analyzer/lib/src/summary2/type_alias.dart
@@ -36,6 +36,7 @@
 
 class _Finder {
   final AstNode self;
+  final Set<AstNode> visited = Set.identity();
   bool hasSelfReference = false;
 
   _Finder(this.self);
@@ -100,10 +101,26 @@
           hasSelfReference = true;
           return;
         }
-        if (typeNode is FunctionTypeAlias) {
-          functionTypeAlias(typeNode);
+        if (typeNode is ClassDeclaration) {
+          if (visited.add(typeNode)) {
+            _typeParameterList(typeNode.typeParameters);
+          }
+        } else if (typeNode is ClassTypeAlias) {
+          if (visited.add(typeNode)) {
+            _typeParameterList(typeNode.typeParameters);
+          }
+        } else if (typeNode is FunctionTypeAlias) {
+          if (visited.add(typeNode)) {
+            functionTypeAlias(typeNode);
+          }
         } else if (typeNode is GenericTypeAlias) {
-          genericTypeAlias(typeNode);
+          if (visited.add(typeNode)) {
+            genericTypeAlias(typeNode);
+          }
+        } else if (typeNode is MixinDeclaration) {
+          if (visited.add(typeNode)) {
+            _typeParameterList(typeNode.typeParameters);
+          }
         }
         _argumentList(node.typeArguments);
       }