Don't add a synthetic dart:core import into itself.

Change-Id: Ieaed83af6e174805c2b124350f7abc72a4a659ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/250116
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index c582c27..c436ab7 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -633,7 +633,10 @@
 
     var unit = parse();
     return _fsState._logger.run('Create unlinked for $path', () {
-      var unlinkedUnit = serializeAstUnlinked2(unit);
+      var unlinkedUnit = serializeAstUnlinked2(
+        unit,
+        isDartCore: uriStr == 'dart:core',
+      );
       var definedNames = computeDefinedNames(unit);
       var referencedNames = computeReferencedNames(unit);
       var subtypedNames = computeSubtypedNames(unit);
@@ -837,7 +840,10 @@
     ];
   }
 
-  static UnlinkedUnit serializeAstUnlinked2(CompilationUnit unit) {
+  static UnlinkedUnit serializeAstUnlinked2(
+    CompilationUnit unit, {
+    required bool isDartCore,
+  }) {
     UnlinkedLibraryDirective? libraryDirective;
     UnlinkedLibraryAugmentationDirective? libraryAugmentationDirective;
     UnlinkedPartOfNameDirective? partOfNameDirective;
@@ -932,7 +938,7 @@
         }
       }
     }
-    if (!hasDartCoreImport) {
+    if (!isDartCore && !hasDartCoreImport) {
       imports.add(
         UnlinkedNamespaceDirective(
           configurations: [],
diff --git a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
index 2d8b725..a08b015 100644
--- a/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/file_state_test.dart
@@ -1451,6 +1451,19 @@
 ''');
   }
 
+  test_newFile_library_dartCore() async {
+    final core = fsStateFor(testFile).getFileForUri(
+      Uri.parse('dart:core'),
+    );
+
+    final coreKind = core.t1!.kind as LibraryFileStateKind;
+    for (final import in coreKind.imports) {
+      if (import.isSyntheticDartCoreImport) {
+        fail('dart:core should not import itself');
+      }
+    }
+  }
+
   test_newFile_library_exports_augmentation() async {
     newFile('$testPackageLibPath/b.dart', r'''
 library augment 'a.dart';
diff --git a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart
index 38fa50e..8891963 100644
--- a/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart
+++ b/pkg/analyzer/test/src/dart/resolution/node_text_expectations.dart
@@ -9,7 +9,7 @@
 import 'package:test_reflective_loader/test_reflective_loader.dart';
 
 class NodeTextExpectationsCollector {
-  static const updatingIsEnabled = true;
+  static const updatingIsEnabled = false;
 
   static const assertMethods = {
     'ContextResolutionTest.assertDriverStateString',