| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2013, 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 // VMOptions=--use_mirrored_compilation_error=true |
| 6 |
| 7 @notDefined |
| 8 library mirrored_compilation_error_test; |
| 9 |
| 10 import 'dart:mirrors'; |
| 11 import "package:expect/expect.dart"; |
| 12 |
| 13 @notDefined |
| 14 class Class<@notDefined T> { |
| 15 @notDefined |
| 16 var field; |
| 17 |
| 18 @notDefined |
| 19 method(@notDefined param) {} |
| 20 } |
| 21 |
| 22 class Class2 { |
| 23 method() { +++; } |
| 24 get getter { +++; } |
| 25 set setter(x) { +++; } |
| 26 |
| 27 static staticFunction() { +++; } |
| 28 static get staticGetter { +++; } |
| 29 static set staticSetter(x) { +++; } |
| 30 |
| 31 Class2() {} |
| 32 Class2.constructor() { +++; } |
| 33 } |
| 34 |
| 35 toplevelFunction() { +++; } |
| 36 get toplevelGetter { +++; } |
| 37 set toplevelSetter(x) { +++; } |
| 38 |
| 39 |
| 40 class G<A extends int, B extends String> { |
| 41 G(); |
| 42 factory G.swap() = G<B,A>; /// static type warning |
| 43 } |
| 44 |
| 45 raises(closure) { |
| 46 Expect.throws(closure, |
| 47 (e) => e is MirroredCompilationError, |
| 48 'Expected a deferred compilation error'); |
| 49 } |
| 50 |
| 51 bool get inCheckedMode { |
| 52 try { |
| 53 var i = 1; |
| 54 String s = i; |
| 55 return false; |
| 56 } catch (e) { |
| 57 return true; |
| 58 } |
| 59 } |
| 60 |
| 61 main() { |
| 62 |
| 63 // Metadata. |
| 64 |
| 65 raises(() => reflectClass(Class).metadata); |
| 66 raises(() => reflectClass(Class).typeVariables.single.metadata); |
| 67 raises(() => reflectClass(Class).variables[#field].metadata); |
| 68 raises(() => reflectClass(Class).methods[#method].metadata); |
| 69 raises(() => reflectClass(Class).methods[#method].parameters.single.metadata); |
| 70 raises(() => reflectClass(Class).owner.metadata); |
| 71 |
| 72 |
| 73 // Invocation. |
| 74 |
| 75 InstanceMirror im = reflect(new Class2()); |
| 76 raises(() => im.invoke(#method, [])); |
| 77 raises(() => im.getField(#getter)); |
| 78 raises(() => im.setField(#setter, 'some value')); |
| 79 // The implementation is within its right to defer the compilation even |
| 80 // further here, so we apply the tear-off to force compilation. |
| 81 raises(() => im.getField(#method).apply([])); |
| 82 |
| 83 ClassMirror cm = reflectClass(Class2); |
| 84 raises(() => cm.invoke(#staticFunction, [])); |
| 85 raises(() => cm.getField(#staticGetter)); |
| 86 raises(() => cm.setField(#staticSetter, 'some value')); |
| 87 raises(() => cm.getField(#staticFunction).apply([])); |
| 88 raises(() => cm.newInstance(#constructor, [])); |
| 89 |
| 90 LibraryMirror lm = reflectClass(Class2).owner; |
| 91 raises(() => lm.invoke(#toplevelFunction, [])); |
| 92 raises(() => lm.getField(#toplevelGetter)); |
| 93 raises(() => lm.setField(#toplevelSetter, 'some value')); |
| 94 raises(() => lm.getField(#toplevelFunction).apply([])); |
| 95 |
| 96 |
| 97 // Bounds violation. |
| 98 |
| 99 if (inCheckedMode) { |
| 100 ClassMirror cm = reflect(new G<int, String>()).type; |
| 101 raises(() => cm.newInstance(#swap, [])); |
| 102 } |
| 103 } |
| OLD | NEW |