OLD | NEW |
(Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 // Regression test for Issue 17141. |
| 6 |
| 7 library test.metadata_nested_constructor_call; |
| 8 |
| 9 import 'dart:mirrors'; |
| 10 import 'package:expect/expect.dart'; |
| 11 |
| 12 class Box { |
| 13 final contents; |
| 14 const Box([this.contents]); |
| 15 } |
| 16 |
| 17 class MutableBox { |
| 18 var contents; |
| 19 MutableBox([this.contents]); // Not const. |
| 20 } |
| 21 |
| 22 @Box() |
| 23 class A {} |
| 24 |
| 25 @Box(const Box()) |
| 26 class B {} |
| 27 |
| 28 @Box(const Box(const Box())) |
| 29 class C {} |
| 30 |
| 31 @Box(const Box(const MutableBox())) /// 01: compile-time error |
| 32 class D {} |
| 33 |
| 34 @Box(const MutableBox(const Box())) /// 02: compile-time error |
| 35 class E {} |
| 36 |
| 37 @Box(Box()) /// 03: compile-time error |
| 38 class F {} |
| 39 |
| 40 @Box(Box(const Box())) /// 04: compile-time error |
| 41 class G {} |
| 42 |
| 43 @Box(Box(const MutableBox())) /// 05: compile-time error |
| 44 class H {} |
| 45 |
| 46 @Box(MutableBox(const Box())) /// 06: compile-time error |
| 47 class I {} |
| 48 |
| 49 final closure = () => 42; |
| 50 @Box(closure()) /// 07: compile-time error |
| 51 class J {} |
| 52 |
| 53 @Box(closure) /// 08: compile-time error |
| 54 class K {} |
| 55 |
| 56 function() => 42; |
| 57 @Box(function()) /// 09: compile-time error |
| 58 class L {} |
| 59 |
| 60 // N.B. This is legal, but @function is not (tested by metadata_allowed_values). |
| 61 @Box(function) |
| 62 class M {} |
| 63 |
| 64 checkMetadata(DeclarationMirror mirror, List expectedMetadata) { |
| 65 Expect.listEquals(expectedMetadata.map(reflect).toList(), mirror.metadata); |
| 66 } |
| 67 |
| 68 main() { |
| 69 closure(); |
| 70 checkMetadata(reflectClass(A), [const Box()]); |
| 71 checkMetadata(reflectClass(B), [const Box(const Box())]); |
| 72 checkMetadata(reflectClass(C), [const Box(const Box(const Box()))]); |
| 73 reflectClass(D).metadata; |
| 74 reflectClass(E).metadata; |
| 75 reflectClass(F).metadata; |
| 76 reflectClass(G).metadata; |
| 77 reflectClass(H).metadata; |
| 78 reflectClass(I).metadata; |
| 79 reflectClass(J).metadata; |
| 80 reflectClass(K).metadata; |
| 81 reflectClass(L).metadata; |
| 82 reflectClass(M).metadata; |
| 83 } |
OLD | NEW |