Issue 35438. When no linked library, fill also _resynthesizedUnits when creating a synthetic library.

There are no linked library because LibraryContext does not add it
if FileState.exists is false. I'm not quite satisfied that we do this,
because everywhere else we pretend that any file exists, but possibly
with empty content.  However we use absence of the linked library
as a signal that `LibraryElement.isSynthetic` should be set. So, we
would need to signal not existing library to resynthesizer in some
other way, or make changes in places where we use `isSynthetic` to
decide whether to report errors.

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

Bug: https://github.com/dart-lang/sdk/issues/35438
Change-Id: I39ad7d173b85a2e0bc7333bb7bee9fad709e0dea
Reviewed-on: https://dart-review.googlesource.com/c/87603
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/summary/resynthesize.dart b/pkg/analyzer/lib/src/summary/resynthesize.dart
index 6b7fa39..ae35bf7 100644
--- a/pkg/analyzer/lib/src/summary/resynthesize.dart
+++ b/pkg/analyzer/lib/src/summary/resynthesize.dart
@@ -339,6 +339,7 @@
         libraryElement.createLoadLibraryFunction(typeProvider);
         libraryElement.publicNamespace = new Namespace({});
         libraryElement.exportNamespace = new Namespace({});
+        _resynthesizedUnits[uri] = {uri: unitElement};
         return libraryElement;
       }
       UnlinkedUnit unlinkedSummary = getUnlinkedSummary(uri);
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index f197f46..12505a4 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -2289,6 +2289,18 @@
         unorderedEquals(['foo', 'main']));
   }
 
+  test_getUnitElement_doesNotExist_afterResynthesized() async {
+    var a = convertPath('/test/lib/a.dart');
+    var b = convertPath('/test/lib/b.dart');
+
+    newFile(a, content: r'''
+import 'package:test/b.dart';
+''');
+
+    await driver.getResolvedLibrary(a);
+    await driver.getUnitElement(b);
+  }
+
   test_getUnitElement_notAbsolutePath() async {
     try {
       await driver.getUnitElement('not_absolute.dart');