| 1 | interface Base { |
| 2 | } |
| 3 | |
| 4 | interface Solid { |
| 5 | Base |
| 6 | } |
| 7 | |
| 8 | interface Dense { |
| 9 | Solid |
| 10 | } |
| 11 | |
| 12 | struct Empty { |
| 13 | } |
| 14 | |
| 15 | fn greet(x Base) bool { |
| 16 | return x is Empty |
| 17 | } |
| 18 | |
| 19 | fn pass_through(x Solid) Base { |
| 20 | return x |
| 21 | } |
| 22 | |
| 23 | fn test_interface_embedding_implicit_upcast() { |
| 24 | solid := Solid(Empty{}) |
| 25 | assert greet(Empty{}) |
| 26 | assert greet(solid) |
| 27 | assert greet(Solid(Empty{})) |
| 28 | base := pass_through(solid) |
| 29 | assert base is Empty |
| 30 | |
| 31 | mut base2 := Base(Empty{}) |
| 32 | base2 = solid |
| 33 | assert base2 is Empty |
| 34 | assert (solid as Base) is Empty |
| 35 | |
| 36 | dense := Dense(Empty{}) |
| 37 | assert greet(dense) |
| 38 | base2 = dense |
| 39 | assert base2 is Empty |
| 40 | assert (dense as Base) is Empty |
| 41 | } |
| 42 | |