OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Test of parameterized factory methods. | 5 // Test of parameterized factory methods. |
6 | 6 |
7 class Foo<T extends num> { | 7 class Foo<T extends num> { |
8 Foo(); | 8 Foo(); |
9 | 9 |
10 factory Foo.bad() = XFoo; // /// 00: static type warning | 10 factory Foo.bad() = XFoo; // //# 00: static type warning |
11 | 11 |
12 factory Foo.good() = Foo; | 12 factory Foo.good() = Foo; |
13 | 13 |
14 factory Foo.IFoo() { return null; } | 14 factory Foo.IFoo() { return null; } |
15 } | 15 } |
16 | 16 |
17 abstract class IFoo<T extends num> { | 17 abstract class IFoo<T extends num> { |
18 factory IFoo() = Foo<T>; | 18 factory IFoo() = Foo<T>; |
19 } | 19 } |
20 | 20 |
21 // String is not assignable to num. | 21 // String is not assignable to num. |
22 class Baz | 22 class Baz |
23 extends Foo<String> /// 01: static type warning, dynamic type error | 23 extends Foo<String> //# 01: static type warning, dynamic type error |
24 {} | 24 {} |
25 | 25 |
26 class Biz extends Foo<int> {} | 26 class Biz extends Foo<int> {} |
27 | 27 |
28 Foo<int> fi; | 28 Foo<int> fi; |
29 | 29 |
30 // String is not assignable to num. | 30 // String is not assignable to num. |
31 Foo | 31 Foo |
32 <String> /// 02: static type warning, dynamic type error | 32 <String> //# 02: static type warning, dynamic type error |
33 fs; | 33 fs; |
34 | 34 |
35 class Box<T> { | 35 class Box<T> { |
36 | 36 |
37 // Box.T is not assignable to num. | 37 // Box.T is not assignable to num. |
38 Foo<T> t; /// 03: static type warning | 38 Foo<T> t; //# 03: static type warning |
39 | 39 |
40 makeFoo() { | 40 makeFoo() { |
41 // Box.T is not assignable to num. | 41 // Box.T is not assignable to num. |
42 return new Foo<T>(); /// 04: static type warning, dynamic type error | 42 return new Foo<T>(); //# 04: static type warning, dynamic type error |
43 } | 43 } |
44 } | 44 } |
45 | 45 |
46 main() { | 46 main() { |
47 // String is not assignable to num. | 47 // String is not assignable to num. |
48 var v1 = new Foo<String>(); /// 05: static type warning, dynamic type error | 48 var v1 = new Foo<String>(); //# 05: static type warning, dynamic type error |
49 | 49 |
50 // String is not assignable to num. | 50 // String is not assignable to num. |
51 Foo<String> v2 = null; /// 06: static type warning | 51 Foo<String> v2 = null; //# 06: static type warning |
52 | 52 |
53 new Baz(); | 53 new Baz(); |
54 new Biz(); | 54 new Biz(); |
55 | 55 |
56 fi = new Foo(); | 56 fi = new Foo(); |
57 fs = new Foo(); | 57 fs = new Foo(); |
58 | 58 |
59 new Box().makeFoo(); | 59 new Box().makeFoo(); |
60 new Box<int>().makeFoo(); | 60 new Box<int>().makeFoo(); |
61 new Box<String>().makeFoo(); | 61 new Box<String>().makeFoo(); |
62 | 62 |
63 // Fisk does not exist. | 63 // Fisk does not exist. |
64 new Box<Fisk>(); /// 07: static type warning | 64 new Box<Fisk>(); //# 07: static type warning |
65 | 65 |
66 // Too many type arguments. | 66 // Too many type arguments. |
67 new Box<Object, Object>(); /// 08: static type warning | 67 new Box<Object, Object>(); //# 08: static type warning |
68 | 68 |
69 // Fisk does not exist. | 69 // Fisk does not exist. |
70 Box<Fisk> box = null; /// 09: static type warning | 70 Box<Fisk> box = null; //# 09: static type warning |
71 | 71 |
72 // Too many type arguments. | 72 // Too many type arguments. |
73 Box<Object, Object> box = null; /// 10: static type warning | 73 Box<Object, Object> box = null; //# 10: static type warning |
74 } | 74 } |
OLD | NEW |