Stop setting element model supertypes in TypeResolverVisitor when using new driver.

It's not necessary (because these types are already set correctly by
the summary linker) and it causes incorrect behavior (because due to
issue #34579 the AST nodes don't always contain correct types).

This reduces the severity of #34579 by ensuring that the incorrect
types stay in the AST nodes and don't leak into the element model.
I'll leave that issue open to remind us to make a more complete fix.

Change-Id: Ibf39370d501b5e19c9dc75713f2c39ca732870d6
Reviewed-on: https://dart-review.googlesource.com/76441
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/error_verifier.dart b/pkg/analyzer/lib/src/generated/error_verifier.dart
index 2f42877..cf3cc20 100644
--- a/pkg/analyzer/lib/src/generated/error_verifier.dart
+++ b/pkg/analyzer/lib/src/generated/error_verifier.dart
@@ -2546,7 +2546,7 @@
         var oldType = interfaces[element];
         if (oldType == null) {
           interfaces[element] = type;
-        } else if (oldType != type) {
+        } else if (!oldType.isEquivalentTo(type)) {
           _errorReporter.reportErrorForNode(
               CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES,
               node,
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 069f66e..2a8bf95 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -8889,6 +8889,13 @@
   /// [nameScope] was computed.
   bool _localModeScopeReady = false;
 
+  /// Indicates whether the ClassElement fields interfaces, mixins, and
+  /// supertype should be set by this visitor.
+  ///
+  /// This is needed when using the old task model, but causes problems with the
+  /// new driver.
+  final bool shouldSetElementSupertypes;
+
   /// Initialize a newly created visitor to resolve the nodes in an AST node.
   ///
   /// [definingLibrary] is the element for the library containing the node being
@@ -8906,7 +8913,8 @@
       TypeProvider typeProvider, AnalysisErrorListener errorListener,
       {Scope nameScope,
       this.mode: TypeResolverMode.everything,
-      bool shouldUseWithClauseInferredTypes: true})
+      bool shouldUseWithClauseInferredTypes: true,
+      this.shouldSetElementSupertypes: false})
       : super(definingLibrary, source, typeProvider, errorListener,
             nameScope: nameScope) {
     _dynamicType = typeProvider.dynamicType;
@@ -9010,7 +9018,7 @@
       superclassType =
           _resolveType(extendsClause.superclass, errorCode, asClass: true);
     }
-    if (classElement != null) {
+    if (shouldSetElementSupertypes && classElement != null) {
       if (superclassType == null) {
         InterfaceType objectType = typeProvider.objectType;
         if (!identical(classElement.type, objectType)) {
@@ -9059,7 +9067,7 @@
       superclassType = typeProvider.objectType;
     }
     ClassElementImpl classElement = _getClassElement(node.name);
-    if (classElement != null) {
+    if (shouldSetElementSupertypes && classElement != null) {
       classElement.supertype = superclassType;
     }
     _resolveWithClause(classElement, node.withClause);
@@ -9512,7 +9520,7 @@
       NodeList<TypeName> interfaces = clause.interfaces;
       List<InterfaceType> interfaceTypes =
           _resolveTypes(interfaces, CompileTimeErrorCode.IMPLEMENTS_NON_CLASS);
-      if (classElement != null) {
+      if (shouldSetElementSupertypes && classElement != null) {
         classElement.interfaces = interfaceTypes;
       }
     }
@@ -9527,7 +9535,9 @@
     if (types == null || types.isEmpty) {
       types = [typeProvider.objectType];
     }
-    classElement.superclassConstraints = types;
+    if (shouldSetElementSupertypes) {
+      classElement.superclassConstraints = types;
+    }
   }
 
   /// Return the [InterfaceType] of the given [typeName].
@@ -9584,7 +9594,9 @@
     if (clause != null) {
       List<InterfaceType> mixinTypes = _resolveTypes(
           clause.mixinTypes, CompileTimeErrorCode.MIXIN_OF_NON_CLASS);
-      classElement.mixins = mixinTypes;
+      if (shouldSetElementSupertypes) {
+        classElement.mixins = mixinTypes;
+      }
     }
   }
 
diff --git a/pkg/analyzer/lib/src/task/dart.dart b/pkg/analyzer/lib/src/task/dart.dart
index 1cedd7a..96e2632 100644
--- a/pkg/analyzer/lib/src/task/dart.dart
+++ b/pkg/analyzer/lib/src/task/dart.dart
@@ -5105,7 +5105,8 @@
     RecordingErrorListener errorListener = new RecordingErrorListener();
     TypeResolverVisitor visitor = new TypeResolverVisitor(
         library, unitElement.source, typeProvider, errorListener,
-        shouldUseWithClauseInferredTypes: false);
+        shouldUseWithClauseInferredTypes: false,
+        shouldSetElementSupertypes: true);
     unit.accept(visitor);
     //
     // Re-write the AST to handle the optional new and const feature.
diff --git a/pkg/analyzer/test/generated/non_error_resolver_driver_test.dart b/pkg/analyzer/test/generated/non_error_resolver_driver_test.dart
index 3639133..c524c9c 100644
--- a/pkg/analyzer/test/generated/non_error_resolver_driver_test.dart
+++ b/pkg/analyzer/test/generated/non_error_resolver_driver_test.dart
@@ -25,12 +25,6 @@
 
   @override
   @failingTest
-  test_infer_mixin_with_substitution_functionType_new_syntax() {
-    return super.test_infer_mixin_with_substitution_functionType_new_syntax();
-  }
-
-  @override
-  @failingTest
   test_intLiteralInDoubleContext_const_exact() {
     return super.test_intLiteralInDoubleContext_const_exact();
   }
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 1c5e584..a786c34 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -1419,7 +1419,7 @@
     _listener.assertNoErrors();
   }
 
-  void setUp() {
+  void setUp({bool shouldSetElementSupertypes: false}) {
     _listener = new GatheringErrorListener();
     MemoryResourceProvider resourceProvider = new MemoryResourceProvider();
     InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(
@@ -1434,7 +1434,8 @@
     libraryScope = new LibraryScope(element);
     _visitor = new TypeResolverVisitor(
         element, librarySource, _typeProvider, _listener,
-        nameScope: libraryScope);
+        nameScope: libraryScope,
+        shouldSetElementSupertypes: shouldSetElementSupertypes);
   }
 
   test_modeApi() async {
@@ -1881,6 +1882,7 @@
     // class B {}
     // class C {}
     // class D {}
+    setUp(shouldSetElementSupertypes: true);
     ClassElement elementA = ElementFactory.classElement2("A");
     ClassElement elementB = ElementFactory.classElement2("B");
     ClassElement elementC = ElementFactory.classElement2("C");
@@ -1910,6 +1912,7 @@
     // class B extends A {
     //   void A() {}
     // }
+    setUp(shouldSetElementSupertypes: true);
     ClassElementImpl elementA = ElementFactory.classElement2("A");
     ClassElementImpl elementB = ElementFactory.classElement2("B");
     elementB.methods = <MethodElement>[