Skip to content

Commit 3d3fdc7

Browse files
chloestefantsovaCommit Queue
authored and
Commit Queue
committed
[cfe] Allow 'Record' in legacy libraries if experiment flag is set
Closes #50511 Change-Id: Ib9a1922cab3ada271beb6958f73342d52d837257 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275701 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 6446fad commit 3d3fdc7

10 files changed

+146
-963
lines changed

pkg/front_end/lib/src/fasta/builder/class_builder.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import '../problems.dart' show internalProblem, unhandled;
2929
import '../scope.dart';
3030
import '../source/source_library_builder.dart';
3131
import '../type_inference/type_schema.dart' show UnknownType;
32+
import '../util/helpers.dart';
3233
import 'builder.dart';
3334
import 'declaration_builder.dart';
3435
import 'library_builder.dart';
@@ -374,7 +375,7 @@ abstract class ClassBuilderImpl extends DeclarationBuilderImpl
374375
libraryBuilder.importUri.scheme == "dart" &&
375376
libraryBuilder.importUri.path == "core" &&
376377
library is SourceLibraryBuilder &&
377-
!library.libraryFeatures.records.isEnabled) {
378+
!isRecordAccessAllowed(library)) {
378379
library.reportFeatureNotEnabled(
379380
library.libraryFeatures.records, fileUri, charOffset, name.length);
380381
return const InvalidType();

pkg/front_end/lib/src/fasta/builder/named_type_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ abstract class NamedTypeBuilder extends TypeBuilder {
402402
DartType aliasedType = _buildAliasedInternal(library, typeUse, hierarchy);
403403

404404
if (library is SourceLibraryBuilder &&
405-
!isRecordAccessAllowed(library.libraryFeatures) &&
405+
!isRecordAccessAllowed(library) &&
406406
isDartCoreRecord(aliasedType)) {
407407
library.reportFeatureNotEnabled(library.libraryFeatures.records,
408408
fileUri ?? library.fileUri, charOffset!, nameText.length);
@@ -418,7 +418,7 @@ abstract class NamedTypeBuilder extends TypeBuilder {
418418
assert(hierarchy != null || isExplicit, "Cannot build $this.");
419419
DartType builtType = _buildAliasedInternal(library, typeUse, hierarchy);
420420
if (library is SourceLibraryBuilder &&
421-
!isRecordAccessAllowed(library.libraryFeatures) &&
421+
!isRecordAccessAllowed(library) &&
422422
isDartCoreRecord(builtType)) {
423423
library.reportFeatureNotEnabled(library.libraryFeatures.records,
424424
fileUri ?? library.fileUri, charOffset!, nameText.length);

pkg/front_end/lib/src/fasta/util/helpers.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,19 @@
55
import 'package:kernel/ast.dart';
66

77
import '../../api_prototype/experimental_flags.dart';
8+
import '../source/source_library_builder.dart';
89

910
abstract class DelayedActionPerformer {
1011
bool get hasDelayedActions;
1112
void performDelayedActions({required bool allowFurtherDelays});
1213
}
1314

1415
/// Returns `true` if access to `Record` from `dart:core` is allowed.
15-
bool isRecordAccessAllowed(LibraryFeatures libraryFeatures) {
16-
return ExperimentalFlag.records.isEnabledByDefault ||
17-
libraryFeatures.records.isEnabled;
16+
bool isRecordAccessAllowed(SourceLibraryBuilder library) {
17+
return library
18+
.loader.target.context.options.globalFeatures.records.isEnabled ||
19+
ExperimentalFlag.records.isEnabledByDefault ||
20+
library.libraryFeatures.records.isEnabled;
1821
}
1922

2023
/// Returns `true` if [type] is `Record` from `dart:core`.

pkg/front_end/testcases/records/type_record_unsupported.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,53 +6,53 @@
66

77
import './type_record_unsupported_lib.dart';
88

9-
typedef R = Record; // Error.
9+
typedef R = Record; // Ok.
1010

11-
typedef AR = A<Record>; // Error.
11+
typedef AR = A<Record>; // Ok.
1212

1313
typedef AR2 = A<FromSupportedR>; // Ok.
1414

1515
typedef AR3 = A<FromSupportedRR>; // Ok.
1616

17-
typedef AR4 = A<FromSupportedAR>; // Ok: indirect use.
17+
typedef AR4 = A<FromSupportedAR>; // Ok.
1818

1919
typedef RR = FromSupportedR; // Ok.
2020

21-
Record foo1() => throw ''; // Error.
21+
Record foo1() => throw ''; // Ok.
2222

2323
dynamic foo2() => new Record(); // Error.
2424

2525
dynamic foo3() => const Record(); // Error.
2626

27-
dynamic foo4() => <Record>[]; // Error.
27+
dynamic foo4() => <Record>[]; // Ok.
2828

29-
dynamic foo5() => Record; // Error.
29+
dynamic foo5() => Record; // Ok.
3030

31-
dynamic foo6() => List<Record>; // Error.
31+
dynamic foo6() => List<Record>; // Ok.
3232

33-
dynamic foo7(Record r) => null; // Error.
33+
dynamic foo7(Record r) => null; // Ok.
3434

35-
dynamic foo8({required Record r}) => null; // Error.
35+
dynamic foo8({required Record r}) => null; // Ok.
3636

37-
List<Record> foo9() => throw ''; // Error.
37+
List<Record> foo9() => throw ''; // Ok.
3838

39-
dynamic foo10(List<Record> l) => null; // Error.
39+
dynamic foo10(List<Record> l) => null; // Ok.
4040

4141
FromSupportedR foo11() => throw ''; // Ok.
4242

43-
FromSupportedAR foo12() => throw ''; // Ok: indirect use.
43+
FromSupportedAR foo12() => throw ''; // Ok.
4444

4545
FromSupportedRR foo13() => throw ''; // Ok.
4646

4747
dynamic foo14(FromSupportedR r) => null; // Ok.
4848

49-
dynamic foo15(FromSupportedAR l) => null; // Ok: indirect use.
49+
dynamic foo15(FromSupportedAR l) => null; // Ok.
5050

5151
dynamic foo16(FromSupportedRR l) => null; // Ok.
5252

5353
dynamic foo17() => FromSupportedR; // Ok.
5454

55-
dynamic foo18() => FromSupportedAR; // Ok: indirect use.
55+
dynamic foo18() => FromSupportedAR; // Ok.
5656

5757
dynamic foo19() => FromSupportedRR; // Ok.
5858

@@ -62,15 +62,15 @@ abstract class A2 implements Record {} // Error.
6262

6363
abstract class A3 with Record {} // Error.
6464

65-
abstract class A4 extends A<Record> {} // Error.
65+
abstract class A4 extends A<Record> {} // Ok.
6666

67-
abstract class A5 implements A<Record> {} // Error.
67+
abstract class A5 implements A<Record> {} // Ok.
6868

69-
abstract class A6 with A<Record> {} // Error.
69+
abstract class A6 with A<Record> {} // Ok.
7070

7171
abstract class A7 extends FromSupportedR {} // Error.
7272

73-
abstract class A8 extends FromSupportedAR {} // Ok: indirect use.
73+
abstract class A8 extends FromSupportedAR {} // Ok.
7474

7575
abstract class A9 extends FromSupportedRR {} // Error.
7676

0 commit comments

Comments
 (0)