| 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 // Tests classes with getters and setters that do not have the same type. |  | 
|   6  |  | 
|   7 class A { |  | 
|   8   int a() { return 37;} |  | 
|   9 } |  | 
|  10  |  | 
|  11 class B extends A{ |  | 
|  12   int b() { return 38; } |  | 
|  13 } |  | 
|  14  |  | 
|  15 class C {} |  | 
|  16  |  | 
|  17 class T1 { |  | 
|  18   A getterField;  |  | 
|  19   A get field() { return getterField; } |  | 
|  20   // OK, B is assignable to A |  | 
|  21   void set field(B arg) { getterField = arg; } |  | 
|  22 } |  | 
|  23  |  | 
|  24 class T2 { |  | 
|  25   A getterField;  |  | 
|  26   C setterField;  |  | 
|  27   A get field() { return getterField; } |  | 
|  28  |  | 
|  29   // Type C is not assignable to A |  | 
|  30   void set field(C arg) { setterField = arg; } /// 01: static type warning |  | 
|  31 } |  | 
|  32  |  | 
|  33 class T3 { |  | 
|  34   B getterField;  |  | 
|  35   B get field() { return getterField; } |  | 
|  36   // OK, A is assignable to B |  | 
|  37   void set field(A arg) { getterField = arg; } |  | 
|  38 } |  | 
|  39  |  | 
|  40  |  | 
|  41 main() { |  | 
|  42   T1 instance1 = new T1(); |  | 
|  43   T2 instance2 = new T2(); /// 01: continued |  | 
|  44   T3 instance3 = new T3(); |  | 
|  45  |  | 
|  46   instance1.field = new B(); |  | 
|  47   A resultA = instance1.field; |  | 
|  48   instance1.field = new A(); /// 03: dynamic type error |  | 
|  49   B resultB = instance1.field; |  | 
|  50  |  | 
|  51   int result; |  | 
|  52   result = instance1.field.a();  |  | 
|  53   Expect.equals(37, result); |  | 
|  54  |  | 
|  55   // Type 'A' has no method named 'b' |  | 
|  56   instance1.field.b(); /// 02: static type warning |  | 
|  57  |  | 
|  58   instance3.field = new B(); |  | 
|  59   result = instance3.field.a(); |  | 
|  60   Expect.equals(37, result); |  | 
|  61   result = instance3.field.b(); |  | 
|  62   Expect.equals(38, result); |  | 
|  63 } |  | 
| OLD | NEW |