| 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 // Dart test for testing super operator calls | 4 // Dart test for testing super operator calls |
| 5 | 5 |
| 6 | 6 |
| 7 class A { | 7 class A { |
| 8 String val = ""; | 8 String val = ""; |
| 9 List things; |
| 10 |
| 11 A() : things = ['D', 'a', 'r', 't', 42]; |
| 12 |
| 9 operator + (String s) { | 13 operator + (String s) { |
| 10 val = val + s; | 14 val = val + s; |
| 11 return this; | 15 return this; |
| 12 } | 16 } |
| 17 |
| 18 operator [] (i) { |
| 19 return things[i]; |
| 20 } |
| 21 |
| 22 operator []= (i, val) { |
| 23 return things[i] = val; |
| 24 } |
| 13 } | 25 } |
| 14 | 26 |
| 27 |
| 15 class B extends A { | 28 class B extends A { |
| 16 operator + (String s) { | 29 operator + (String s) { |
| 17 super + (s + s); | 30 super + (s + s); // Call A.operator+(this, s + s). |
| 18 return this; | 31 return this; |
| 19 } | 32 } |
| 33 |
| 34 operator [] (i) { |
| 35 var temp = super[i]; |
| 36 return temp + temp; |
| 37 } |
| 38 |
| 39 operator []= (i, val) { |
| 40 // Make sure the index expression is only evaluated |
| 41 // once in the presence of a compound assignment. |
| 42 return super[i++] += val; |
| 43 } |
| 44 |
| 20 } | 45 } |
| 21 | 46 |
| 22 main () { | 47 main () { |
| 23 var a = new A(); | 48 var a = new A(); |
| 24 a = a + "William"; | 49 a = a + "William"; // operator + of class A. |
| 25 Expect.equals("William", a.val); | 50 Expect.equals("William", a.val); |
| 51 Expect.equals("r", a[2]); // operator [] of class A. |
| 26 | 52 |
| 27 a = new B(); | 53 a = new B(); |
| 28 a += "Tell"; | 54 a += "Tell"; // operator + of class B. |
| 29 Expect.equals("TellTell", a.val); | 55 Expect.equals("TellTell", a.val); |
| 56 Expect.equals("rr", a[2]); // operator [] of class B. |
| 57 |
| 58 a[4] = 1; // operator []= of class B. |
| 59 Expect.equals(43, a.things[4]); |
| 60 Expect.equals(86, a[4]); |
| 61 |
| 30 } | 62 } |
| OLD | NEW |