Skip to content

Commit d4a8100

Browse files
chloestefantsovaCommit Bot
authored and
Commit Bot
committed
[cfe] Implement subtype relationship for record types
Part of #49713 Change-Id: I736a4e4f4ba09a80dda1409a1c6640a64ab560f4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256480 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent e811801 commit d4a8100

File tree

9 files changed

+322
-17
lines changed

9 files changed

+322
-17
lines changed

pkg/front_end/messages.status

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,6 @@ DuplicatedNamedArgument/example: Fail
217217
DuplicatedParameterName/example: Fail
218218
DuplicatedRecordLiteralFieldName/analyzerCode: Fail
219219
DuplicatedRecordTypeFieldName/analyzerCode: Fail
220-
EmptyRecordTypeFieldsList/part_wrapped_script: Crash # Missing subtyping for record types
221-
EmptyRecordTypeFieldsList/script: Crash # Missing subtyping for record types
222-
EmptyRecordTypeNamedFieldsList/part_wrapped_script: Crash # Missing subtyping for record types
223-
EmptyRecordTypeNamedFieldsList/script: Crash # Missing subtyping for record types
224220
Encoding/analyzerCode: Fail
225221
EnumAbstractMember/analyzerCode: Fail
226222
EnumAbstractMember/example: Fail
@@ -752,8 +748,6 @@ NullableTearoffError/analyzerCode: Fail
752748
NullableTearoffError/example: Fail
753749
NullableTearoffWarning/analyzerCode: Fail
754750
NullableTearoffWarning/example: Fail
755-
OnlyOneRecordTypeFieldsList/part_wrapped_script: Crash # Missing subtyping for record types
756-
OnlyOneRecordTypeFieldsList/script: Crash # Missing subtyping for record types
757751
OperatorMinusParameterMismatch/example: Fail
758752
OperatorParameterMismatch0/analyzerCode: Fail
759753
OperatorParameterMismatch0/example: Fail

pkg/front_end/messages.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ EmptyRecordTypeFieldsList:
330330
experiments: records
331331
script: >
332332
main() {
333-
(/*missing*/) record = (1, 2,);
333+
(/*missing*/) record = ((1, 2,) as dynamic);
334334
}
335335
336336
EmptyRecordTypeNamedFieldsList:
@@ -350,7 +350,7 @@ OnlyOneRecordTypeFieldsList:
350350
experiments: records
351351
script: >
352352
main() {
353-
(int /*missing*/) record = (1, 2,);
353+
(int /*missing*/) record = ((1, 2,) as dynamic);
354354
}
355355
356356
DuplicatedRecordTypeFieldName:

pkg/front_end/test/fasta/types/kernel_type_parser_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class String extends self::Object {
7676
}
7777
class bool extends self::Object {
7878
}
79+
class Record extends self::Object {
80+
}
7981
class DefaultTypes<S extends self::Object? = dynamic, T extends self::Object, U extends self::List<self::DefaultTypes::S%> = self::List<dynamic>, V extends self::List<self::DefaultTypes::T> = self::List<self::Object>, W extends self::Comparable<self::DefaultTypes::W> = self::Comparable<dynamic>, X extends (self::DefaultTypes::W) → void = (Never) → void, Y extends () → self::DefaultTypes::W = () → self::Comparable<dynamic>> extends self::Object {
8082
}
8183
class Super extends self::Object implements self::Comparable<self::Sub> {

pkg/front_end/test/fasta/types/shared_type_tests.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,5 +1071,61 @@ abstract class SubtypeTest<T, E> {
10711071
isSubtype("ExtendedClass", "Extension");
10721072
isSubtype("ExtendedGenericClass<num>", "GenericExtension<num>");
10731073
isSubtype("ExtendedSubclass", "Extension");
1074+
1075+
// Records.
1076+
isSubtype("Never", "(int, String)");
1077+
isSubtype("(int, String)", "Object");
1078+
isSubtype("(int, String)", "(Object, Object)");
1079+
isSubtype("(Never, Never)", "(int, String)");
1080+
isSubtype("(int, String)", "(num, Object)");
1081+
isSubtype("Never", "(int, {String foo})");
1082+
isSubtype("(int, {String foo})", "Object");
1083+
isSubtype("(int, {String foo})", "(Object, {Object foo})");
1084+
isSubtype("(Never, {Never foo})", "(int, {String foo})");
1085+
isSubtype("(int, {String foo})", "(num, {Object foo})");
1086+
isObliviousSubtype("Null", "(int, String)");
1087+
isNotSubtype("(int, String)", "Null");
1088+
isNotSubtype("(int, String, bool)", "(int, String)");
1089+
isNotSubtype("(int, String)", "(int, String, bool)");
1090+
isNotSubtype("(int, {String foo})", "(int, {String foo, bool bar})");
1091+
isNotSubtype("(int, {String foo, bool bar})", "(int, {String foo})");
1092+
isNotSubtype("(int, Never)", "Never");
1093+
isSubtype("((int, String), bool)", "((num, Object), Object)");
1094+
isNotSubtype("((int, String), bool)", "(num, (Object, Object))");
1095+
isSubtype("(int, String)", "Record");
1096+
isSubtype("(int, {String foo})", "Record");
1097+
isSubtype("({int foo, String bar})", "Record");
1098+
isNotSubtype("Record", "(int, String)");
1099+
isSubtype("Record", "Object");
1100+
isSubtype("Never", "Record");
1101+
isObliviousSubtype("Null", "Record");
1102+
isNotSubtype("(int, String)", "Function");
1103+
isNotSubtype("Function", "(int, String)");
1104+
isNotSubtype("(int, String)", "(int, String) -> void");
1105+
isNotSubtype("(int, String) -> void", "(int, String)");
1106+
isNotSubtype("(int, String)", "int");
1107+
isNotSubtype("int", "(int, String)");
1108+
isSubtype("(int, String)", "FutureOr<(int, String)>");
1109+
isNotSubtype("FutureOr<(int, String)>", "(int, String)");
1110+
isSubtype("T", "(int, String)", typeParameters: "T extends (int, String)");
1111+
isNotSubtype("(int, String)", "T",
1112+
typeParameters: "T extends (int, String)");
1113+
isSubtype("T & (int, String)", "(int, String)",
1114+
typeParameters: "T extends Record");
1115+
isSubtype("T & (int, String)", "(int, String)",
1116+
typeParameters: "T extends Object?");
1117+
isSubtype("T & (int, double)", "(num, num)",
1118+
typeParameters: "T extends Record");
1119+
isSubtype("T & (int, double)", "(num, num)",
1120+
typeParameters: "T extends Object?");
1121+
isNotSubtype("(int, String)", "T & (int, String)",
1122+
typeParameters: "T extends Record");
1123+
isNotSubtype("(int, String)", "T & (int, String)",
1124+
typeParameters: "T extends Object?");
1125+
isSubtype("(int, String)", "(int, String)?");
1126+
isObliviousSubtype("(int, String)?", "(int, String)");
1127+
isSubtype("Null", "(int, String)?");
1128+
isObliviousSubtype("Null", "(int, String)");
1129+
isObliviousSubtype("(int, String)?", "Record");
10741130
}
10751131
}

pkg/kernel/lib/core_types.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ class CoreTypes {
134134

135135
late final Class functionClass = index.getClass('dart:core', 'Function');
136136

137+
late final Class recordClass = index.getClass('dart:core', 'Record');
138+
137139
late final Class futureClass = index.getClass('dart:core', 'Future');
138140

139141
late final Procedure futureSyncFactory =

0 commit comments

Comments
 (0)