OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017, 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 // Dart test for type checks involving the void type. | |
Leaf
2017/02/23 21:30:52
Are these strong mode, Dart 1.0, or both?
eernst
2017/07/10 16:05:34
In Dart 1.x it is a static warning if m2 overrides
| |
6 | |
7 import 'package:expect/expect.dart'; | |
8 | |
9 use<T>(T x) {} | |
10 | |
11 class A<T> { | |
12 T x; | |
13 Object y; | |
Leaf
2017/02/23 21:30:52
Is it worth also have a dynamic version to make it
| |
14 int z; | |
15 | |
16 T foo() => null; | |
17 void bar() {} | |
18 void gee(T x) {} | |
19 | |
20 f(A<Object> a) {} | |
21 g(A<void> a) {} | |
22 h(A<T> a) {} | |
23 } | |
24 | |
25 class B implements A<Object> { | |
26 void /// 00: error | |
eernst
2017/07/10 16:05:34
This would be a static warning for Dart 1.x.
| |
27 /* /// 00: continued | |
28 var | |
29 */ /// 00: continued | |
30 x; | |
31 | |
32 void /// 00b: error | |
eernst
2017/07/10 16:05:34
This would be a static warning for Dart 1.x.
| |
33 /* /// 00b: continued | |
34 var | |
35 */ /// 00b: continued | |
36 y; | |
37 | |
38 void /// 00c: error | |
eernst
2017/07/10 16:05:34
This would be a static warning for Dart 1.x.
| |
39 /* /// 00c: continued | |
40 int | |
41 */ /// 00c: continued | |
42 z; | |
43 | |
44 // Overriding an Object function with a void function is an error. | |
45 void /// 01: error | |
eernst
2017/07/10 16:05:34
This would be a static warning for Dart 1.x.
| |
46 foo() => null; | |
47 | |
48 int bar() => 499; | |
49 void gee(void x) {} | |
50 f(A<void> a) {} | |
51 g(A<void> a) {} | |
52 h(A<void> a) {} | |
eernst
2017/07/10 16:05:34
(Just noting that these overriding declarations ar
| |
53 } | |
54 | |
55 class C implements A<void> { | |
56 void x; | |
57 Object y; | |
58 int z; | |
59 | |
60 void foo() {} | |
61 void bar() {} | |
62 void gee(void x) { | |
63 use(x); /// 03: error | |
64 } | |
65 | |
66 f(C c) {} | |
67 g(C c) {} | |
68 h(C c) {} | |
69 } | |
70 | |
71 class D implements A<void> { | |
72 Object x; /// 04: ok? should be ok, but the setter goes from void to Object . | |
Leaf
2017/02/23 21:30:53
I think not ok, at least not as we've formulated t
eernst
2017/07/11 08:45:43
The informal spec of generalized void is built on
| |
73 Object y; | |
74 int z; | |
75 | |
76 Object foo() => null; | |
77 void bar() {} | |
78 void gee( | |
79 Object /// 05: error | |
eernst
2017/07/11 08:45:43
We will only get an error here if we introduce a n
| |
80 x) {} | |
81 | |
82 f(A<Object> a) {} | |
83 g( | |
84 A<Object> /// 06: error | |
eernst
2017/07/11 08:45:43
This parameter type was declared as `A<void>` in `
| |
85 a) {} | |
86 h( | |
87 A<Object> /// 07: error | |
eernst
2017/07/11 08:45:43
This parameter type was declared as `A<T>` in `A<T
| |
88 a) {} | |
89 } | |
90 | |
91 void instantiateClasses() { | |
92 var a = new A<void>(); | |
93 var b = new B(); | |
94 var c = new C(); | |
95 var d = new D(); | |
96 | |
97 a.foo(); | |
98 b.foo(); | |
99 c.foo(); | |
100 d.foo(); | |
101 a.bar(); | |
102 b.bar(); | |
103 c.bar(); | |
104 d.bar(); | |
105 a.gee(499); | |
106 b.gee(499); | |
107 c.gee(499); | |
108 d.gee(499); | |
109 } | |
110 | |
111 void testAssignments() { | |
112 A<void> a1 = new A<Object>(); | |
113 A<Object> a2 = new | |
114 A | |
115 <void> /// implicit_downcast: error | |
Leaf
2017/02/23 21:30:53
What does this mean? Implicit downcasts aren't er
eernst
2017/07/11 08:45:43
This can only be an error with full support for vo
| |
116 (); | |
117 A a3 = new A<void>(); /// raw_assignment: ok? | |
Leaf
2017/02/23 21:30:53
There should be no difference between this one and
eernst
2017/07/11 08:45:43
Since we don't have voidness preservation at this
| |
118 A<dynamic> a4 = new A<void>(); /// A_dynamic_assignment: ok? | |
Leaf
2017/02/23 21:30:53
ditto.
eernst
2017/07/11 08:45:43
Same as line 117.
| |
119 dynamic a5 = new A<void>(); /// dynamic_assignment: ok? | |
eernst
2017/07/11 08:45:43
Since we don't have voidness preservation at this
| |
120 } | |
121 | |
122 main() { | |
123 instantiateClasses(); | |
124 testAssignments(); | |
125 } | |
OLD | NEW |