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. |
| 6 |
| 7 import 'package:expect/expect.dart'; |
| 8 |
| 9 use<T>(T x) {} |
| 10 |
| 11 class A<T> { |
| 12 T x; |
| 13 Object y; |
| 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: static type warning |
| 27 /* /// 00: continued |
| 28 var |
| 29 */ /// 00: continued |
| 30 x; |
| 31 |
| 32 void /// 00b: static type warning |
| 33 /* /// 00b: continued |
| 34 var |
| 35 */ /// 00b: continued |
| 36 y; |
| 37 |
| 38 void /// 00c: static type warning |
| 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: static type warning |
| 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) {} |
| 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: static type warning |
| 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: static type warning |
| 73 Object y; |
| 74 int z; |
| 75 |
| 76 Object foo() => null; |
| 77 void bar() {} |
| 78 void gee( |
| 79 Object /// 05: static type warning |
| 80 x) {} |
| 81 |
| 82 f(A<Object> a) {} |
| 83 g( |
| 84 A<Object> /// 06: static type warning |
| 85 a) {} |
| 86 h( |
| 87 A<Object> /// 07: static type warning |
| 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 A<void>(); |
| 114 A a3 = new A<void>(); |
| 115 A<dynamic> a4 = new A<void>(); |
| 116 dynamic a5 = new A<void>(); |
| 117 } |
| 118 |
| 119 main() { |
| 120 instantiateClasses(); |
| 121 testAssignments(); |
| 122 } |
OLD | NEW |