OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Regression test for Issue 17141. | 5 // Regression test for Issue 17141. |
6 | 6 |
7 library test.metadata_nested_constructor_call; | 7 library test.metadata_nested_constructor_call; |
8 | 8 |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
11 | 11 |
12 class Box { | 12 class Box { |
13 final contents; | 13 final contents; |
14 const Box([this.contents]); | 14 const Box([this.contents]); |
15 } | 15 } |
16 | 16 |
17 class MutableBox { | 17 class MutableBox { |
18 var contents; | 18 var contents; |
19 MutableBox([this.contents]); // Not const. | 19 MutableBox([this.contents]); // Not const. |
20 } | 20 } |
21 | 21 |
22 @Box() | 22 @Box() |
23 class A {} | 23 class A {} |
24 | 24 |
25 @Box(const Box()) | 25 @Box(const Box()) |
26 class B {} | 26 class B {} |
27 | 27 |
28 @Box(const Box(const Box())) | 28 @Box(const Box(const Box())) |
29 class C {} | 29 class C {} |
(...skipping 10 matching lines...) Expand all Loading... |
40 @Box(Box(const Box())) // //# 04: compile-time error | 40 @Box(Box(const Box())) // //# 04: compile-time error |
41 class G {} | 41 class G {} |
42 | 42 |
43 @Box(Box(const MutableBox())) // //# 05: compile-time error | 43 @Box(Box(const MutableBox())) // //# 05: compile-time error |
44 class H {} | 44 class H {} |
45 | 45 |
46 @Box(MutableBox(const Box())) // //# 06: compile-time error | 46 @Box(MutableBox(const Box())) // //# 06: compile-time error |
47 class I {} | 47 class I {} |
48 | 48 |
49 final closure = () => 42; | 49 final closure = () => 42; |
| 50 |
50 @Box(closure()) // //# 07: compile-time error | 51 @Box(closure()) // //# 07: compile-time error |
51 class J {} | 52 class J {} |
52 | 53 |
53 @Box(closure) // //# 08: compile-time error | 54 @Box(closure) // //# 08: compile-time error |
54 class K {} | 55 class K {} |
55 | 56 |
56 function() => 42; | 57 function() => 42; |
| 58 |
57 @Box(function()) // //# 09: compile-time error | 59 @Box(function()) // //# 09: compile-time error |
58 class L {} | 60 class L {} |
59 | 61 |
60 // N.B. This is legal, but @function is not (tested by metadata_allowed_values). | 62 // N.B. This is legal, but @function is not (tested by metadata_allowed_values). |
61 @Box(function) | 63 @Box(function) |
62 class M {} | 64 class M {} |
63 | 65 |
64 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | 66 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { |
65 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); | 67 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); |
66 } | 68 } |
67 | 69 |
68 main() { | 70 main() { |
69 closure(); | 71 closure(); |
70 checkMetadata(reflectClass(A), [const Box()]); | 72 checkMetadata(reflectClass(A), [const Box()]); |
71 checkMetadata(reflectClass(B), [const Box(const Box())]); | 73 checkMetadata(reflectClass(B), [const Box(const Box())]); |
72 checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]); | 74 checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]); |
73 reflectClass(D).metadata; | 75 reflectClass(D).metadata; |
74 reflectClass(E).metadata; | 76 reflectClass(E).metadata; |
75 reflectClass(F).metadata; | 77 reflectClass(F).metadata; |
76 reflectClass(G).metadata; | 78 reflectClass(G).metadata; |
77 reflectClass(H).metadata; | 79 reflectClass(H).metadata; |
78 reflectClass(I).metadata; | 80 reflectClass(I).metadata; |
79 reflectClass(J).metadata; | 81 reflectClass(J).metadata; |
80 reflectClass(K).metadata; | 82 reflectClass(K).metadata; |
81 reflectClass(L).metadata; | 83 reflectClass(L).metadata; |
82 reflectClass(M).metadata; | 84 reflectClass(M).metadata; |
83 } | 85 } |
OLD | NEW |