|
| 1 | +package unit; |
| 2 | + |
| 3 | +abstract class Dispatcher { |
| 4 | + public var scheduler(get, never):Float; |
| 5 | + |
| 6 | + abstract function get_scheduler():Float; |
| 7 | +} |
| 8 | + |
| 9 | +class ConcreteDispatcher extends Dispatcher { |
| 10 | + @:isVar public var scheduler(get, null):Int; |
| 11 | + |
| 12 | + public function new(v:Int) { |
| 13 | + this.scheduler = v; |
| 14 | + } |
| 15 | + |
| 16 | + function get_scheduler() { |
| 17 | + return scheduler; |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +class ParentWithNonPhysical { |
| 22 | + public function new() {} |
| 23 | + |
| 24 | + public var name(get, private set):String; |
| 25 | + |
| 26 | + function get_name():String |
| 27 | + return "parent"; |
| 28 | + |
| 29 | + function set_name(v:String):String |
| 30 | + return "parent"; |
| 31 | +} |
| 32 | + |
| 33 | +class ChildWidened extends ParentWithNonPhysical { |
| 34 | + @:isVar public var name(get, set):String; |
| 35 | + |
| 36 | + public function new(v:String) { |
| 37 | + super(); |
| 38 | + this.name = v; |
| 39 | + } |
| 40 | + |
| 41 | + override function get_name():String |
| 42 | + return name; |
| 43 | + |
| 44 | + override function set_name(v:String):String |
| 45 | + return name = v; |
| 46 | +} |
| 47 | + |
| 48 | +class ChildWidenedNonPhysical extends ParentWithNonPhysical { |
| 49 | + public var name(get, set):String; |
| 50 | + |
| 51 | + public function new() { |
| 52 | + super(); |
| 53 | + } |
| 54 | + |
| 55 | + override function get_name():String |
| 56 | + return "child"; |
| 57 | + |
| 58 | + override function set_name(v:String):String |
| 59 | + return v; |
| 60 | +} |
| 61 | + |
| 62 | +class TestRedefinition extends Test { |
| 63 | + public function testDispatcher() { |
| 64 | + final dispatcher = new ConcreteDispatcher(123); |
| 65 | + eq(dispatcher.scheduler, 123); |
| 66 | + final generalDispatcher:Dispatcher = dispatcher; |
| 67 | + eq(generalDispatcher.scheduler, 123.0); |
| 68 | + } |
| 69 | + |
| 70 | + public function testWidening() { |
| 71 | + final child = new ChildWidened("child"); |
| 72 | + eq(child.name, "child"); |
| 73 | + child.name = "new child"; |
| 74 | + eq(child.name, "new child"); |
| 75 | + |
| 76 | + final parent:ParentWithNonPhysical = child; |
| 77 | + eq(parent.name, "new child"); |
| 78 | + } |
| 79 | + |
| 80 | + public function testWideningNonPhysical() { |
| 81 | + final child = new ChildWidenedNonPhysical(); |
| 82 | + eq(child.name, "child"); |
| 83 | + child.name = "new child"; |
| 84 | + |
| 85 | + final parent:ParentWithNonPhysical = child; |
| 86 | + eq(parent.name, "child"); |
| 87 | + } |
| 88 | +} |
0 commit comments