OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
eernst
2017/09/04 17:04:57
Lost coverage: don't delete this 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 // Test instantiation of object with malbounded types. | |
6 | |
7 class A< | |
8 T | |
9 extends num //# 01: static type warning | |
10 > {} | |
11 | |
12 class B<T> implements A<T> {} | |
13 | |
14 class C< | |
15 T | |
16 extends num //# 01: continued | |
17 > implements B<T> {} | |
18 | |
19 class Class<T> { | |
20 newA() { | |
21 new A<T>(); //# 01: continued | |
22 } | |
23 newB() { | |
24 new B<T>(); //# 01: continued | |
25 } | |
26 newC() { | |
27 new C<T>(); //# 01: continued | |
28 } | |
29 } | |
30 | |
31 bool inCheckedMode() { | |
32 try { | |
33 var i = 42; | |
34 String s = i; | |
35 } on TypeError catch (e) { | |
36 return true; | |
37 } | |
38 return false; | |
39 } | |
40 | |
41 void test(bool expectTypeError, f()) { | |
42 try { | |
43 var v = f(); | |
44 if (expectTypeError && inCheckedMode()) { | |
45 throw 'Missing type error instantiating ${v.runtimeType}'; | |
46 } | |
47 } on TypeError catch (e) { | |
48 if (!expectTypeError || !inCheckedMode()) { | |
49 throw 'Unexpected type error: $e'; | |
50 } | |
51 } | |
52 } | |
53 | |
54 void main() { | |
55 test(false, () => new A<int>()); | |
56 test(false, () => new B<int>()); | |
57 test(false, () => new C<int>()); | |
58 | |
59 test(true, () => new A<String>()); //# 01: continued | |
60 test(true, () => new B<String>()); //# 01: continued | |
61 test(true, () => new C<String>()); //# 01: continued | |
62 | |
63 var c = new Class<int>(); | |
64 test(false, () => c.newA()); | |
65 test(false, () => c.newB()); | |
66 test(false, () => c.newC()); | |
67 | |
68 c = new Class<String>(); | |
69 test(true, () => c.newA()); //# 01: continued | |
70 test(true, () => c.newB()); //# 01: continued | |
71 test(true, () => c.newC()); //# 01: continued | |
72 } | |
OLD | NEW |