Remove analyzer Dart files from AnalysisDriver.

This caused language_2/malformed2_test being flaky.

R=brianwilkerson@google.com

Change-Id: I8bf813e3244e9a76ea2ff72cd9c10b9516596a79
Reviewed-on: https://dart-review.googlesource.com/65980
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index c9de631..545ded6 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -268,6 +268,7 @@
     }
 
     // These are used to do part file analysis across sources.
+    Set<String> dartFiles = new Set<String>();
     Set<FileState> libraryFiles = new Set<FileState>();
     Set<FileState> danglingParts = new Set<FileState>();
 
@@ -375,6 +376,7 @@
             // If the file cannot be analyzed, ignore it.
           }
         } else {
+          dartFiles.add(path);
           var file = analysisDriver.fsState.getFileForPath(path);
 
           if (file.isPart) {
@@ -396,6 +398,13 @@
       }
     }
 
+    // We are done analyzing this batch of files.
+    // The next batch should not be affected by a previous batch.
+    // E.g. the same parts in both batches, but with different libraries.
+    for (var path in dartFiles) {
+      analysisDriver.removeFile(path);
+    }
+
     // Any dangling parts still in this list were definitely dangling.
     for (FileState partFile in danglingParts) {
       reportPartError(partFile.path);