Fix invalidating part specified via package uri via file uri

In the incremental compiler, if asking to invalidate a file via a file
uri, where the corresponding file is a part that has been used via its
package uri (as in "part 'package:foo/whatever.dart'"), we should still
invalidate it.

Before we didn't because we 'translated' the part uri to a 'file uri'
except it was still a package uri.
Now we do.

Change-Id: I276c6e7c772d6167178fa8b6594417d37d1dd1c4
Reviewed-on: https://dart-review.googlesource.com/c/85344
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Peter von der Ahé <ahe@google.com>
diff --git a/pkg/front_end/lib/src/fasta/incremental_compiler.dart b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
index 2565d7e..c4d089a 100644
--- a/pkg/front_end/lib/src/fasta/incremental_compiler.dart
+++ b/pkg/front_end/lib/src/fasta/incremental_compiler.dart
@@ -622,6 +622,12 @@
         for (LibraryPart part in library.target.parts) {
           Uri partUri = library.uri.resolve(part.partUri);
           Uri fileUri = library.library.fileUri.resolve(part.partUri);
+          if (fileUri.scheme == "package") {
+            // Part was specified via package URI and the resolve above thus
+            // did not go as expected. Translate the package URI to get the
+            // actual file URI.
+            fileUri = uriTranslator.translate(partUri, false);
+          }
           if (isInvalidated(partUri, fileUri)) {
             invalidatedImportUris.add(partUri);
             builders[partUri] = library;
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/invalidate_package_part_from_package_url_as_file.yaml b/pkg/front_end/testcases/incremental_initialize_from_dill/invalidate_package_part_from_package_url_as_file.yaml
new file mode 100644
index 0000000..d5a757b
--- /dev/null
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/invalidate_package_part_from_package_url_as_file.yaml
@@ -0,0 +1,25 @@
+# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE.md file.
+
+# Test that invalidating a part of a package works with package URI when the
+# part file was referenced via a package URI
+
+type: basic
+entry: "package:example/main.dart"
+strong: false
+invalidate:
+  - pkg/example/b.dart
+sources:
+  pkg/example/main.dart: |
+    part "package:example/b.dart";
+    main() {
+      print("hello");
+      b();
+    }
+  pkg/example/b.dart: |
+    part of "package:example/main.dart";
+    b() {
+      print("b1");
+    }
+  .packages: example:pkg/example
diff --git a/pkg/front_end/testcases/incremental_initialize_from_dill/invalidate_package_part_from_package_url_as_package.yaml b/pkg/front_end/testcases/incremental_initialize_from_dill/invalidate_package_part_from_package_url_as_package.yaml
new file mode 100644
index 0000000..149b1ae
--- /dev/null
+++ b/pkg/front_end/testcases/incremental_initialize_from_dill/invalidate_package_part_from_package_url_as_package.yaml
@@ -0,0 +1,25 @@
+# Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
+# for details. All rights reserved. Use of this source code is governed by a
+# BSD-style license that can be found in the LICENSE.md file.
+
+# Test that invalidating a part of a package works with package URI when the
+# part file was referenced via a package URI
+
+type: basic
+entry: "package:example/main.dart"
+strong: false
+invalidate:
+  - "package:example/b.dart"
+sources:
+  pkg/example/main.dart: |
+    part "package:example/b.dart";
+    main() {
+      print("hello");
+      b();
+    }
+  pkg/example/b.dart: |
+    part of "package:example/main.dart";
+    b() {
+      print("b1");
+    }
+  .packages: example:pkg/example