Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; | |
| 6 | |
| 7 // Test of final fields generating implicit setters that throw. | |
| 8 | |
| 9 String x = "toplevel"; // Should never be read in this test. | |
| 10 | |
| 11 class B { | |
| 12 var x = 37; | |
| 13 } | |
| 14 | |
| 15 class C extends B { | |
| 16 final x = 42; | |
| 17 | |
| 18 // Local access should work the same as direct access. | |
| 19 get cx => x; | |
| 20 void set cx(value) { x = value; } // Should throw if used. | |
|
Lasse Reichstein Nielsen
2013/10/09 11:08:39
I think this line should be a static warning becau
| |
| 21 | |
| 22 // Super access should work. | |
| 23 get bx => super.x; | |
| 24 void set bx(value) { super.x = value; } | |
| 25 | |
| 26 noSuchMethod(i) => "noSuchMethod"; // Should never be called in this test. | |
| 27 } | |
| 28 | |
| 29 // Class with only final field has setter in implicit interface. | |
| 30 class A { | |
| 31 final int x = 42; | |
| 32 } | |
| 33 | |
| 34 // Should get warning because the implicit interface contains the setter, | |
| 35 // and this non-abstract class doesn't. | |
| 36 class AI | |
| 37 implements A /// 01: static type warning | |
| 38 { | |
| 39 int get x => 37; | |
| 40 } | |
| 41 | |
| 42 // Erases static type information. Used to avoid *static* warnings when | |
| 43 // using a setter for a final field. | |
| 44 erase(x) => x; | |
| 45 | |
| 46 void main() { | |
| 47 Expect.equals(42, new C().x); | |
| 48 Expect.throws(() { erase(new C()).x = 10; }); | |
| 49 Expect.equals(42, new C().cx); | |
| 50 Expect.throws(() { erase(new C()).cx = 10; }); | |
| 51 Expect.equals(37, new C().bx); | |
| 52 Expect.equals(10, (erase(new C())..bx = 10).bx); | |
| 53 | |
| 54 Expect.equals(42, new A().x); | |
| 55 Expect.throws(() { erase(new A()).x = 10; }); | |
| 56 Expect.equals(37, new AI().x); | |
| 57 Expect.throws(() { erase(new AI()).x = 10; }); | |
| 58 | |
| 59 Expect.equals("toplevel", x); // Should not have changed. | |
| 60 } | |
| OLD | NEW |