| 1 | interface Eq { |
| 2 | eq(other Eq) bool |
| 3 | } |
| 4 | |
| 5 | interface Ord { |
| 6 | Eq |
| 7 | lt(other Ord) bool |
| 8 | } |
| 9 | |
| 10 | // implement Ord for Int |
| 11 | struct Int { |
| 12 | value int |
| 13 | } |
| 14 | |
| 15 | fn (i Int) eq(other Ord) bool { |
| 16 | if other is Int { |
| 17 | return i.value == other.value |
| 18 | } |
| 19 | return false |
| 20 | } |
| 21 | |
| 22 | fn (i Int) lt(other Ord) bool { |
| 23 | if other is Int { |
| 24 | return i.value < other.value |
| 25 | } |
| 26 | return false |
| 27 | } |
| 28 | |
| 29 | fn compare(x Ord, y Ord) { |
| 30 | println(x.eq(y)) |
| 31 | assert !x.eq(y) |
| 32 | println(x.lt(y)) |
| 33 | assert x.lt(y) |
| 34 | } |
| 35 | |
| 36 | fn test_interface_embedding_with_interface_para() { |
| 37 | compare(Int{1}, Int{2}) |
| 38 | } |
| 39 | |