| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Check that const objects (including literals) are immutable. | 4 // Check that const objects (including literals) are immutable. |
| 5 | 5 |
| 6 class A { | 6 class A { |
| 7 const A(this.x, this.y); | 7 const A(this.x, this.y); |
| 8 final num x, y; | 8 final num x, y; |
| 9 } | 9 } |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 var list = const [1, 2]; | 12 var list = const [1, 2]; |
| 13 Expect.throws(() => list[0] = 3); | 13 Expect.throws(() => list[0] = 3); |
| 14 Expect.equals(1, list[0]); | 14 Expect.equals(1, list[0]); |
| 15 | 15 |
| 16 var m = const { 'foo': 499 }; | 16 var m = const { 'foo': 499 }; |
| 17 Expect.throws(() => m['foo'] = 42); | 17 Expect.throws(() => m['foo'] = 42); |
| 18 Expect.equals(499, m['foo']); | 18 Expect.equals(499, m['foo']); |
| 19 | 19 |
| 20 var a1 = const A(1, 2); | 20 var a1 = const A(1, 2); |
| 21 Expect.throws(() => a1.x = 499); | 21 Expect.throws(() => a1.x = 499); |
| 22 Expect.equals(1, a1.x); | 22 Expect.equals(1, a1.x); |
| 23 | 23 |
| 24 A a2 = const A(1, 2); | 24 A a2 = const A(1, 2); |
| 25 Expect.throws(() => a2.x = 499); | 25 Expect.throws(() => a2.x = 499); |
| 26 Expect.equals(1, a2.x); | 26 Expect.equals(1, a2.x); |
| 27 } | 27 } |
| OLD | NEW |