| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 // VMOptions=--enable_type_checks | |
| 5 // | |
| 6 // Dart test program testing type checks in list literals. | |
| 7 | |
| 8 class ListLiteral4Test<T> { | |
| 9 test() { | |
| 10 int result = 0; | |
| 11 try { | |
| 12 var m = <String>[0, 1]; // 0 is not a String. | |
| 13 } catch (TypeError error) { | |
| 14 result += 1; | |
| 15 } | |
| 16 try { | |
| 17 var m = <int>[0, 1]; | |
| 18 m["0"] = 1; // "0" is not an int. | |
| 19 } catch (TypeError error) { | |
| 20 result += 10; | |
| 21 } | |
| 22 try { | |
| 23 var m = <T>["a", "b"]; // "b" is not an int. | |
| 24 } catch (TypeError error) { | |
| 25 result += 100; | |
| 26 } | |
| 27 try { | |
| 28 var m = <T>[0, 1]; // OK. | |
| 29 } catch (TypeError error) { | |
| 30 result += 1000; | |
| 31 } | |
| 32 try { | |
| 33 var m = <T>[0, 1]; | |
| 34 m["0"] = 1; // "0" is not an int. | |
| 35 } catch (TypeError error) { | |
| 36 result += 10000; | |
| 37 } | |
| 38 try { | |
| 39 var m = const <int>[0, 1]; | |
| 40 m["0"] = 1; // "0" is not an int. | |
| 41 } catch (TypeError error) { | |
| 42 result += 100000; | |
| 43 } | |
| 44 return result; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 main() { | |
| 49 var t = new ListLiteral4Test<int>(); | |
| 50 Expect.equals(110111, t.test()); | |
| 51 } | |
| 52 | |
| 53 | |
| OLD | NEW |