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 non strong-mode, `FutureOr` should just behave like dynamic. | |
6 | |
7 import 'dart:async'; | |
8 import 'package:expect/expect.dart'; | |
9 | |
10 void foo(FutureOr x) {} | |
11 FutureOr bar() => 499; | |
12 | |
13 void foo2(FutureOr<String> x) {} | |
14 FutureOr<int> bar2() => 499; | |
15 | |
16 void foo3(String x) {} | |
17 int bar3() => 499; | |
18 | |
19 typedef void FunTakes<T>(T x); | |
20 typedef T FunReturns<T>(); | |
21 | |
22 main() { | |
23 Expect.isTrue(499 is FutureOr); | |
24 Expect.isTrue(499 is FutureOr<String>); | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is! or Expect.isFalse?
floitsch
2016/12/08 18:41:55
not in non-strong mode.
| |
25 Expect.isTrue(499 is FutureOr<int>); | |
26 | |
27 Expect.isTrue(new Future.value(499) is FutureOr); | |
28 Expect.isTrue(new Future.value(499) is FutureOr<int>); | |
29 Expect.isTrue(new Future.value(499) is FutureOr<String>); | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
This is spec mode, so it's a Future<dynamic> which
floitsch
2016/12/08 18:41:55
The whole test is for spec mode. This is hinted by
Lasse Reichstein Nielsen
2016/12/08 19:31:00
No, that's just me being too used to think of Futu
| |
30 | |
31 Expect.isTrue(foo is FunTakes<dynamic>); | |
32 Expect.isTrue(foo is FunTakes<Object>); | |
33 Expect.isTrue(foo is FunTakes<int>); | |
34 Expect.isTrue(foo is FunTakes<String>); | |
35 Expect.isTrue(foo is FunTakes<Future<int>>); | |
36 Expect.isTrue(foo is FunTakes<Future<String>>); | |
37 Expect.isTrue(foo is FunTakes<FutureOr<Object>>); | |
38 Expect.isTrue(foo is FunTakes<FutureOr<int>>); | |
39 Expect.isTrue(foo is FunTakes<FutureOr<String>>); | |
40 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<Object>>>); | |
41 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<int>>>); | |
42 Expect.isTrue(foo is FunTakes<FutureOr<FutureOr<String>>>); | |
43 | |
44 Expect.isTrue(bar is FunReturns<dynamic>); | |
45 Expect.isTrue(bar is FunReturns<Object>); | |
46 Expect.isTrue(bar is FunReturns<int>); | |
47 Expect.isTrue(bar is FunReturns<String>); | |
48 Expect.isTrue(bar is FunReturns<Future<int>>); | |
49 Expect.isTrue(bar is FunReturns<Future<String>>); | |
50 Expect.isTrue(bar is FunReturns<FutureOr<Object>>); | |
51 Expect.isTrue(bar is FunReturns<FutureOr<int>>); | |
52 Expect.isTrue(bar is FunReturns<FutureOr<String>>); | |
53 Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<Object>>>); | |
54 Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<int>>>); | |
55 Expect.isTrue(bar is FunReturns<FutureOr<FutureOr<String>>>); | |
56 | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
You could move the declaration of foo2 down here s
floitsch
2016/12/08 18:41:55
Done.
| |
57 Expect.isTrue(foo2 is FunTakes<dynamic>); | |
58 Expect.isTrue(foo2 is FunTakes<Object>); | |
59 Expect.isTrue(foo2 is FunTakes<int>); | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
floitsch
2016/12/08 18:41:55
Not, if `FutureOr` is equivalent to dynamic (which
| |
60 Expect.isTrue(foo2 is FunTakes<String>); | |
61 Expect.isTrue(foo2 is FunTakes<Future<int>>); | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
More below (everyone except Future<String>, F
floitsch
2016/12/08 18:41:55
Same answer.
| |
62 Expect.isTrue(foo2 is FunTakes<Future<String>>); | |
63 Expect.isTrue(foo2 is FunTakes<FutureOr<Object>>); | |
64 Expect.isTrue(foo2 is FunTakes<FutureOr<int>>); | |
65 Expect.isTrue(foo2 is FunTakes<FutureOr<String>>); | |
66 Expect.isTrue(foo2 is FunTakes<FutureOr<FutureOr<Object>>>); | |
67 Expect.isTrue(foo2 is FunTakes<FutureOr<FutureOr<int>>>); | |
68 Expect.isTrue(foo2 is FunTakes<FutureOr<FutureOr<String>>>); | |
69 | |
70 Expect.isTrue(bar2 is FunReturns<dynamic>); | |
71 Expect.isTrue(bar2 is FunReturns<Object>); | |
72 Expect.isTrue(bar2 is FunReturns<int>); | |
73 Expect.isTrue(bar2 is FunReturns<String>); | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
Same for Future<String>, FutureOr<String>, an
floitsch
2016/12/08 18:41:55
Same answer.
| |
74 Expect.isTrue(bar2 is FunReturns<Future<int>>); | |
75 Expect.isTrue(bar2 is FunReturns<Future<String>>); | |
76 Expect.isTrue(bar2 is FunReturns<FutureOr<Object>>); | |
77 Expect.isTrue(bar2 is FunReturns<FutureOr<int>>); | |
78 Expect.isTrue(bar2 is FunReturns<FutureOr<String>>); | |
79 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<Object>>>); | |
80 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<int>>>); | |
81 Expect.isTrue(bar2 is FunReturns<FutureOr<FutureOr<String>>>); | |
82 | |
83 Expect.isTrue(foo3 is FunTakes<dynamic>); | |
84 Expect.isTrue(foo3 is FunTakes<Object>); | |
Lasse Reichstein Nielsen
2016/12/08 18:20:28
is!
(Just figure out the rest :)
floitsch
2016/12/08 18:41:55
No. In Dart1, foo3 *is* a function that takes `Obj
| |
85 Expect.isFalse(foo3 is FunTakes<int>); | |
86 Expect.isTrue(foo3 is FunTakes<String>); | |
87 Expect.isFalse(foo3 is FunTakes<Future<int>>); | |
88 Expect.isFalse(foo3 is FunTakes<Future<String>>); | |
89 Expect.isTrue(foo3 is FunTakes<FutureOr<Object>>); | |
90 Expect.isTrue(foo3 is FunTakes<FutureOr<int>>); | |
91 Expect.isTrue(foo3 is FunTakes<FutureOr<String>>); | |
92 Expect.isTrue(foo3 is FunTakes<FutureOr<FutureOr<Object>>>); | |
93 Expect.isTrue(foo3 is FunTakes<FutureOr<FutureOr<int>>>); | |
94 Expect.isTrue(foo3 is FunTakes<FutureOr<FutureOr<String>>>); | |
95 | |
96 Expect.isTrue(bar3 is FunReturns<dynamic>); | |
97 Expect.isTrue(bar3 is FunReturns<Object>); | |
98 Expect.isTrue(bar3 is FunReturns<int>); | |
99 Expect.isFalse(bar3 is FunReturns<String>); | |
100 Expect.isFalse(bar3 is FunReturns<Future<int>>); | |
101 Expect.isFalse(bar3 is FunReturns<Future<String>>); | |
102 Expect.isTrue(bar3 is FunReturns<FutureOr<Object>>); | |
103 Expect.isTrue(bar3 is FunReturns<FutureOr<int>>); | |
104 Expect.isTrue(bar3 is FunReturns<FutureOr<String>>); | |
105 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<Object>>>); | |
106 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<int>>>); | |
107 Expect.isTrue(bar3 is FunReturns<FutureOr<FutureOr<String>>>); | |
108 } | |
OLD | NEW |