| 1 | module main |
| 2 | |
| 3 | // Define a simple interface |
| 4 | pub interface Node { |
| 5 | kind() int |
| 6 | name() string |
| 7 | } |
| 8 | |
| 9 | // Implement the interface |
| 10 | pub struct MyNode { |
| 11 | pub: |
| 12 | value int |
| 13 | text string |
| 14 | } |
| 15 | |
| 16 | pub fn (n MyNode) kind() int { |
| 17 | return 1 |
| 18 | } |
| 19 | |
| 20 | pub fn (n MyNode) name() string { |
| 21 | return n.text |
| 22 | } |
| 23 | |
| 24 | // Define a type alias to the interface |
| 25 | pub type Expr = Node |
| 26 | |
| 27 | // Function using the type alias |
| 28 | pub fn process_node(expr Expr) string { |
| 29 | return expr.name() |
| 30 | } |
| 31 | |
| 32 | fn test_alias_interface() { |
| 33 | node := MyNode{ |
| 34 | value: 42 |
| 35 | text: 'test' |
| 36 | } |
| 37 | result := process_node(node) |
| 38 | println('Result: ${result}') |
| 39 | assert result == 'test' |
| 40 | } |
| 41 | |