Skip to content

Commit d8f9283

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
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 <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent eb9554d commit d8f9283

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ class ClassElementImpl extends ClassOrMixinElementImpl implements ClassElement {
676676
return name == 'Object' && library.isDartCore;
677677
}
678678

679+
bool get isDartCoreRecord {
680+
return name == 'Record' && library.isDartCore;
681+
}
682+
679683
bool get isEnumLike {
680684
// Must be a concrete class.
681685
// TODO(scheglov) `is MixinElement` after the separation.

pkg/analyzer/lib/src/dart/element/scope.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:analyzer/dart/analysis/features.dart';
56
import 'package:analyzer/dart/element/element.dart';
67
import 'package:analyzer/dart/element/scope.dart';
78
import 'package:analyzer/src/dart/element/element.dart';
@@ -191,6 +192,14 @@ class PrefixScope implements Scope {
191192
}
192193

193194
void _add(Element element, bool isFromDeprecatedExport) {
195+
// TODO(scheglov) Remove when `records` feature is enabled by default.
196+
if (element is ClassElementImpl &&
197+
element.isDartCoreRecord &&
198+
!_container.featureSet.isEnabled(Feature.records) &&
199+
Feature.records.status != FeatureStatus.current) {
200+
return;
201+
}
202+
194203
if (element is PropertyAccessorElement && element.isSetter) {
195204
_addTo(element, isFromDeprecatedExport, isSetter: true);
196205
} else {

pkg/analyzer/test/src/diagnostics/undefined_class_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,22 @@ f() { new C(); }
208208
]);
209209
}
210210

211+
test_Record() async {
212+
await assertNoErrorsInCode('''
213+
void f(Record r) {}
214+
''');
215+
}
216+
217+
test_Record_language218() async {
218+
// TODO(scheglov) Update when `records` feature is enabled by default.
219+
await assertErrorsInCode('''
220+
// @dart = 2.18
221+
void f(Record r) {}
222+
''', [
223+
error(CompileTimeErrorCode.UNDEFINED_CLASS, 23, 6),
224+
]);
225+
}
226+
211227
test_variableDeclaration() async {
212228
await assertErrorsInCode('''
213229
f() { C c; }

0 commit comments

Comments
 (0)