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 | |
51 @Box(closure()) // //# 07: compile-time error | 50 @Box(closure()) // //# 07: compile-time error |
52 class J {} | 51 class J {} |
53 | 52 |
54 @Box(closure) // //# 08: compile-time error | 53 @Box(closure) // //# 08: compile-time error |
55 class K {} | 54 class K {} |
56 | 55 |
57 function() => 42; | 56 function() => 42; |
58 | |
59 @Box(function()) // //# 09: compile-time error | 57 @Box(function()) // //# 09: compile-time error |
60 class L {} | 58 class L {} |
61 | 59 |
62 // N.B. This is legal, but @function is not (tested by metadata_allowed_values). | 60 // N.B. This is legal, but @function is not (tested by metadata_allowed_values). |
63 @Box(function) | 61 @Box(function) |
64 class M {} | 62 class M {} |
65 | 63 |
66 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { | 64 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { |
67 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); | 65 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); |
68 } | 66 } |
69 | 67 |
70 main() { | 68 main() { |
71 closure(); | 69 closure(); |
72 checkMetadata(reflectClass(A), [const Box()]); | 70 checkMetadata(reflectClass(A), [const Box()]); |
73 checkMetadata(reflectClass(B), [const Box(const Box())]); | 71 checkMetadata(reflectClass(B), [const Box(const Box())]); |
74 checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]); | 72 checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]); |
75 reflectClass(D).metadata; | 73 reflectClass(D).metadata; |
76 reflectClass(E).metadata; | 74 reflectClass(E).metadata; |
77 reflectClass(F).metadata; | 75 reflectClass(F).metadata; |
78 reflectClass(G).metadata; | 76 reflectClass(G).metadata; |
79 reflectClass(H).metadata; | 77 reflectClass(H).metadata; |
80 reflectClass(I).metadata; | 78 reflectClass(I).metadata; |
81 reflectClass(J).metadata; | 79 reflectClass(J).metadata; |
82 reflectClass(K).metadata; | 80 reflectClass(K).metadata; |
83 reflectClass(L).metadata; | 81 reflectClass(L).metadata; |
84 reflectClass(M).metadata; | 82 reflectClass(M).metadata; |
85 } | 83 } |
OLD | NEW |