OLD | NEW |
| (Empty) |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // In strong mode, `FutureOr` should be equivalent to the union of `Future<T>` | |
6 // and `T`. | |
7 | |
8 import 'dart:async'; | |
9 import 'package:expect/expect.dart'; | |
10 | |
11 typedef void FunTakes<T>(T x); | |
12 typedef T FunReturns<T>(); | |
13 | |
14 main() { | |
15 Expect.isTrue(499 is FutureOr); // Same as `is Object`. | |
16 Expect.isTrue(499 is FutureOr<int>); | |
17 Expect.isFalse(499 is FutureOr<String>); | |
18 | |
19 Expect.isTrue(new Future.value(499) is FutureOr); // Same as `is Object`. | |
20 Expect.isTrue(new Future.value(499) is FutureOr<int>); | |
21 Expect.isFalse(new Future.value(499) is FutureOr<String>); | |
22 | |
23 void foo(FutureOr x) {} // Equivalent to `void bar(Object x) {}`. | |
24 | |
25 // A function that takes Object takes everything. | |
26 Expect.isTrue(foo is FunTakes<dynamic>); | |
27 Expect.isTrue(foo is FunTakes<Object>); | |
28 Expect.isTrue(foo is FunTakes<int>); | |
29 Expect.isTrue(foo is FunTakes<String>); | |
30 Expect.isTrue(foo is FunTakes<Future<int>>); | |
31 Expect.isTrue(foo is FunTakes<Future<String>>); | |
32 Expect.isTrue(foo is FunTakes<FutureOr<Object>>); | |
33 Expect.isTrue(foo is FunTakes<FutureOr<int>>); | |
34 Expect.isTrue(foo is FunTakes<FutureOr<String>>); | |
35 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<Object>>>); | |
36 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<int>>>); | |
37 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<String>>>); | |
38 | |
39 FutureOr bar() => 499; // Equivalent to `Object foo() => 499`. | |
40 | |
41 Expect.isTrue(bar is FunReturns<dynamic>); | |
42 Expect.isTrue(bar is FunReturns<Object>); | |
43 Expect.isFalse(bar is FunReturns<int>); | |
44 Expect.isFalse(bar is FunReturns<String>); | |
45 Expect.isFalse(bar is FunReturns<Future<int>>); | |
46 Expect.isFalse(bar is FunReturns<Future<String>>); | |
47 Expect.isTrue(bar is FunReturns<FutureOr<Object>>); | |
48 Expect.isFalse(bar is FunReturns<FutureOr<int>>); | |
49 Expect.isFalse(bar is FunReturns<FutureOr<String>>); | |
50 Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<Object>>>); | |
51 Expect.isFalse(bar is FunReturns<FutureOr<FutureOr<int>>>); | |
52 Expect.isFalse(bar is FunReturns<FutureOr<FutureOr<String>>>); | |
53 | |
54 void foo2(FutureOr<String> x) {} | |
55 | |
56 // In is-checks `dynamic` is treat specially (counting as bottom in parameter | |
57 // positions). | |
58 Expect.isTrue(foo2 is FunTakes<dynamic>); | |
59 | |
60 Expect.isFalse(foo2 is FunTakes<Object>); | |
61 Expect.isFalse(foo2 is FunTakes<int>); | |
62 Expect.isTrue(foo2 is FunTakes<String>); | |
63 Expect.isFalse(foo2 is FunTakes<Future<int>>); | |
64 Expect.isTrue(foo2 is FunTakes<Future<String>>); | |
65 Expect.isFalse(foo2 is FunTakes<FutureOr<Object>>); | |
66 Expect.isFalse(foo2 is FunTakes<FutureOr<int>>); | |
67 Expect.isTrue(foo2 is FunTakes<FutureOr<String>>); | |
68 Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<Object>>>); | |
69 Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<int>>>); | |
70 Expect.isFalse(foo2 is FunTakes<FutureOr<FutureOr<String>>>); | |
71 | |
72 FutureOr<int> bar2() => 499; | |
73 | |
74 Expect.isTrue(bar2 is FunReturns<dynamic>); | |
75 Expect.isTrue(bar2 is FunReturns<Object>); | |
76 Expect.isFalse(bar2 is FunReturns<int>); | |
77 Expect.isFalse(bar2 is FunReturns<String>); | |
78 Expect.isFalse(bar2 is FunReturns<Future<int>>); | |
79 Expect.isFalse(bar2 is FunReturns<Future<String>>); | |
80 Expect.isTrue(bar2 is FunReturns<FutureOr<Object>>); | |
81 Expect.isTrue(bar2 is FunReturns<FutureOr<int>>); | |
82 Expect.isFalse(bar2 is FunReturns<FutureOr<String>>); | |
83 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<Object>>>); | |
84 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<int>>>); | |
85 Expect.isFalse(bar2 is FunReturns<FutureOr<FutureOr<String>>>); | |
86 | |
87 void foo3(String x) {} | |
88 | |
89 // In is-checks `dynamic` is treat specially (counting as bottom in parameter | |
90 // positions). | |
91 Expect.isTrue(foo3 is FunTakes<dynamic>); | |
92 | |
93 Expect.isFalse(foo3 is FunTakes<Object>); | |
94 Expect.isFalse(foo3 is FunTakes<int>); | |
95 Expect.isTrue(foo3 is FunTakes<String>); | |
96 Expect.isFalse(foo3 is FunTakes<Future<int>>); | |
97 Expect.isFalse(foo3 is FunTakes<Future<String>>); | |
98 Expect.isFalse(foo3 is FunTakes<FutureOr<Object>>); | |
99 Expect.isFalse(foo3 is FunTakes<FutureOr<int>>); | |
100 Expect.isFalse(foo3 is FunTakes<FutureOr<String>>); | |
101 Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<Object>>>); | |
102 Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<int>>>); | |
103 Expect.isFalse(foo3 is FunTakes<FutureOr<FutureOr<String>>>); | |
104 | |
105 int bar3() => 499; | |
106 | |
107 Expect.isTrue(bar3 is FunReturns<dynamic>); | |
108 Expect.isTrue(bar3 is FunReturns<Object>); | |
109 Expect.isTrue(bar3 is FunReturns<int>); | |
110 Expect.isFalse(bar3 is FunReturns<String>); | |
111 Expect.isFalse(bar3 is FunReturns<Future<int>>); | |
112 Expect.isFalse(bar3 is FunReturns<Future<String>>); | |
113 Expect.isTrue(bar3 is FunReturns<FutureOr<Object>>); | |
114 Expect.isTrue(bar3 is FunReturns<FutureOr<int>>); | |
115 Expect.isFalse(bar3 is FunReturns<FutureOr<String>>); | |
116 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<Object>>>); | |
117 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<int>>>); | |
118 Expect.isFalse(bar3 is FunReturns<FutureOr<FutureOr<String>>>); | |
119 } | |
OLD | NEW |