Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Unified Diff: pkg/kernel/test/type_subtype_test.dart

Issue 2900113002: Implement subtyping rules for FutureOr in kernel. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/kernel/test/type_subtype_test.dart
diff --git a/pkg/kernel/test/type_subtype_test.dart b/pkg/kernel/test/type_subtype_test.dart
index b34db7dd6143eb3c441667dddfd17a58794382b7..7e1b5fdd85f529a1c91afabf548b5e98f47ed256 100644
--- a/pkg/kernel/test/type_subtype_test.dart
+++ b/pkg/kernel/test/type_subtype_test.dart
@@ -16,6 +16,8 @@ var classEnvironment = <String, List<String>>{
'double': ['num'],
'Iterable<T>': ['Object'],
'List<T>': ['Iterable<T>'],
+ 'Future<T>': ['Object'],
+ 'FutureOr<T>': ['Object'],
};
List<TestCase> testCases = <TestCase>[
@@ -84,43 +86,76 @@ List<TestCase> testCases = <TestCase>[
notSubtype('<E>(E,List<Object>) => List<E>', '<F:List<F>>(F,F) => F'),
notSubtype('<E>(E,List<Object>) => int', '<F:List<F>>(F,F) => F'),
subtype('<E>(E,List<Object>) => E', '<F:List<F>>(F,F) => void'),
+
+ subtype('int', 'FutureOr<int>', strongMode: true),
+ subtype('int', 'FutureOr<num>', strongMode: true),
+ subtype('Future<int>', 'FutureOr<int>', strongMode: true),
+ subtype('Future<int>', 'FutureOr<num>', strongMode: true),
+ subtype('Future<int>', 'FutureOr<Object>', strongMode: true),
+ subtype('FutureOr<int>', 'FutureOr<int>', strongMode: true),
+ subtype('FutureOr<int>', 'FutureOr<num>', strongMode: true),
+ subtype('FutureOr<int>', 'Object', strongMode: true),
+ notSubtype('int', 'FutureOr<double>', strongMode: true),
+ notSubtype('FutureOr<double>', 'int', strongMode: true),
+ notSubtype('FutureOr<int>', 'Future<num>', strongMode: true),
+ notSubtype('FutureOr<int>', 'num', strongMode: true),
];
/// Assert that [subtype] is a subtype of [supertype], and that [supertype]
/// is not a subtype of [subtype] (unless the two strings are equal).
-TestCase subtype(String subtype_, String supertype) {
- return new TestCase(subtype_, supertype, isSubtype: true);
+TestCase subtype(String subtype_, String supertype, {bool strongMode: false}) {
+ return new TestCase(subtype_, supertype,
+ isSubtype: true, strongMode: strongMode);
}
/// Assert that neither type is a subtype of the other.
-TestCase notSubtype(String subtype_, String supertype) {
- return new TestCase(subtype_, supertype, isSubtype: false);
+TestCase notSubtype(String subtype_, String supertype,
+ {bool strongMode: false}) {
+ return new TestCase(subtype_, supertype,
+ isSubtype: false, strongMode: strongMode);
}
class TestCase {
String subtype;
String supertype;
bool isSubtype;
- TestCase(this.subtype, this.supertype, {this.isSubtype});
+ bool strongMode;
+
+ TestCase(this.subtype, this.supertype,
+ {this.isSubtype, this.strongMode: false});
- String toString() =>
- isSubtype ? '$subtype <: $supertype' : '$subtype </: $supertype';
+ String toString() {
+ var description =
+ isSubtype ? '$subtype <: $supertype' : '$subtype </: $supertype';
+ if (strongMode) {
+ description += ' (strong mode)';
+ }
+ return description;
+ }
}
class MockSubtypeTester extends SubtypeTester {
ClassHierarchy hierarchy;
InterfaceType objectType;
InterfaceType rawFunctionType;
+ Class futureClass;
+ Class futureOrClass;
LazyTypeEnvironment environment;
+ bool strongMode = false;
+
+ InterfaceType futureType(DartType type) =>
+ new InterfaceType(futureClass, [type]);
- MockSubtypeTester(
- this.hierarchy, this.objectType, this.rawFunctionType, this.environment);
+ MockSubtypeTester(this.hierarchy, this.objectType, this.rawFunctionType,
+ this.futureClass, this.futureOrClass, this.environment);
}
MockSubtypeTester makeSubtypeTester(Map<String, List<String>> testcase) {
LazyTypeEnvironment environment = new LazyTypeEnvironment();
Class objectClass = environment.lookup('Object');
Class functionClass = environment.lookup('Function');
+ Class futureClass = environment.lookup('Future');
+ Class futureOrClass = environment.lookup('FutureOr');
functionClass.supertype = objectClass.asRawSupertype;
for (var typeString in testcase.keys) {
InterfaceType type = environment.parseFresh(typeString);
@@ -138,8 +173,8 @@ MockSubtypeTester makeSubtypeTester(Map<String, List<String>> testcase) {
}
var program = new Program(libraries: [environment.dummyLibrary]);
var hierarchy = new ClassHierarchy(program);
- return new MockSubtypeTester(
- hierarchy, objectClass.rawType, functionClass.rawType, environment);
+ return new MockSubtypeTester(hierarchy, objectClass.rawType,
+ functionClass.rawType, futureClass, futureOrClass, environment);
}
main() {
@@ -147,6 +182,7 @@ main() {
var environment = tester.environment;
for (var testCase in testCases) {
test('$testCase', () {
+ tester.strongMode = testCase.strongMode;
var subtype = environment.parseFresh(testCase.subtype);
var supertype = environment.parseFresh(testCase.supertype);
if (tester.isSubtypeOf(subtype, supertype) != testCase.isSubtype) {
« pkg/kernel/lib/type_environment.dart ('K') | « pkg/kernel/lib/type_environment.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698