Don't add parts without 'part of' as libraries.

See also https://github.com/dart-lang/sdk/issues/33587

R=brianwilkerson@google.com, paulberry@google.com

Change-Id: I109c76c88483c6b9459fe94b372c71bec8b2d6bf
Reviewed-on: https://dart-review.googlesource.com/61962
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart b/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
index 0e174e3..03f505c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/frontend_resolution.dart
@@ -223,12 +223,28 @@
 
         // Add new libraries to the current component.
         if (newComponent != null) {
+          // When a file is used in a `part` directive of a library, but does
+          // not have a `part of` itself, we get this file both as a part,
+          // and as a library. This causes an exception later in resolution.
+          var partFileUris = new Set<Uri>();
           for (var library in newComponent.libraries) {
-            Uri uri = library.importUri;
-            if (!_component.root.hasChild('$uri')) {
-              _component.root.getChildFromUri(uri).bindTo(library.reference);
-              library.computeCanonicalNames();
-              _component.libraries.add(library);
+            var libraryFileUri = library.fileUri;
+            for (var part in library.parts) {
+              var partFileUri = libraryFileUri.resolve(part.partUri);
+              if (partFileUri != libraryFileUri) {
+                partFileUris.add(partFileUri);
+              }
+            }
+          }
+          // Do add new libraries.
+          for (var library in newComponent.libraries) {
+            if (!partFileUris.contains(library.fileUri)) {
+              Uri uri = library.importUri;
+              if (!_component.root.hasChild('$uri')) {
+                _component.root.getChildFromUri(uri).bindTo(library.reference);
+                library.computeCanonicalNames();
+                _component.libraries.add(library);
+              }
             }
           }
         }
diff --git a/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart
index 0350db4..67aa952 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code_kernel_test.dart
@@ -2256,13 +2256,6 @@
 
   @override
   @failingTest
-  @potentialAnalyzerProblem
-  test_partOfNonPart() async {
-    await super.test_partOfNonPart();
-  }
-
-  @override
-  @failingTest
   test_prefix_assignment_compound_in_method() async {
     // Bad state: No reference information for p at 46
     await super.test_prefix_assignment_compound_in_method();
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_kernel_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_kernel_test.dart
index a65d133..4bb1b75 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_kernel_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_kernel_test.dart
@@ -31,15 +31,6 @@
   @override
   bool get useCFE => true;
 
-//  @failingTest
-//  @potentialAnalyzerProblem
-  @override
-  @failingTest
-  @potentialAnalyzerProblem
-  test_analyze_resolveDirectives_error_partOfNonPart() async {
-    await super.test_analyze_resolveDirectives_error_partOfNonPart();
-  }
-
   @override
   test_asyncChangesDuringAnalysis_getErrors() async {
     // TODO(brianwilkerson) Re-enable this test. It was disabled because it