Don't import class Record from dart:core into a library where the 'records' feature is not enabled.

...while it is still an experiment.

Change-Id: Ib606a3c099b45343686b8e921c0aa1c24dec59da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/261920
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/element.dart b/pkg/analyzer/lib/src/dart/element/element.dart
index d571004..ad47b82 100644
--- a/pkg/analyzer/lib/src/dart/element/element.dart
+++ b/pkg/analyzer/lib/src/dart/element/element.dart
@@ -676,6 +676,10 @@
     return name == 'Object' && library.isDartCore;
   }
 
+  bool get isDartCoreRecord {
+    return name == 'Record' && library.isDartCore;
+  }
+
   bool get isEnumLike {
     // Must be a concrete class.
     // TODO(scheglov) `is MixinElement` after the separation.
diff --git a/pkg/analyzer/lib/src/dart/element/scope.dart b/pkg/analyzer/lib/src/dart/element/scope.dart
index d1d6cb0..be08afa 100644
--- a/pkg/analyzer/lib/src/dart/element/scope.dart
+++ b/pkg/analyzer/lib/src/dart/element/scope.dart
@@ -2,6 +2,7 @@
 // for details. All rights reserved. Use of this source code is governed by a
 // BSD-style license that can be found in the LICENSE file.
 
+import 'package:analyzer/dart/analysis/features.dart';
 import 'package:analyzer/dart/element/element.dart';
 import 'package:analyzer/dart/element/scope.dart';
 import 'package:analyzer/src/dart/element/element.dart';
@@ -191,6 +192,14 @@
   }
 
   void _add(Element element, bool isFromDeprecatedExport) {
+    // TODO(scheglov) Remove when `records` feature is enabled by default.
+    if (element is ClassElementImpl &&
+        element.isDartCoreRecord &&
+        !_container.featureSet.isEnabled(Feature.records) &&
+        Feature.records.status != FeatureStatus.current) {
+      return;
+    }
+
     if (element is PropertyAccessorElement && element.isSetter) {
       _addTo(element, isFromDeprecatedExport, isSetter: true);
     } else {
diff --git a/pkg/analyzer/test/src/diagnostics/undefined_class_test.dart b/pkg/analyzer/test/src/diagnostics/undefined_class_test.dart
index ce2d86a..ee4beab 100644
--- a/pkg/analyzer/test/src/diagnostics/undefined_class_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/undefined_class_test.dart
@@ -208,6 +208,22 @@
     ]);
   }
 
+  test_Record() async {
+    await assertNoErrorsInCode('''
+void f(Record r) {}
+''');
+  }
+
+  test_Record_language218() async {
+    // TODO(scheglov) Update when `records` feature is enabled by default.
+    await assertErrorsInCode('''
+// @dart = 2.18
+void f(Record r) {}
+''', [
+      error(CompileTimeErrorCode.UNDEFINED_CLASS, 23, 6),
+    ]);
+  }
+
   test_variableDeclaration() async {
     await assertErrorsInCode('''
 f() { C c; }