| 1 | // Chained aliases (`type B = A` where `A` is itself an alias, #27055) let |
| 2 | // modules re-export types from their dependencies without leaking the original |
| 3 | // module name to callers. |
| 4 | |
| 5 | type Id = int |
| 6 | type UserId = Id |
| 7 | type AdminId = UserId |
| 8 | |
| 9 | struct Box { |
| 10 | v int |
| 11 | } |
| 12 | |
| 13 | type Wrapped = Box |
| 14 | type DoubleWrapped = Wrapped |
| 15 | |
| 16 | fn test_primitive_chain() { |
| 17 | a := AdminId(42) |
| 18 | b := UserId(a) |
| 19 | c := Id(b) |
| 20 | assert int(c) == 42 |
| 21 | assert int(a) == 42 |
| 22 | } |
| 23 | |
| 24 | fn test_struct_chain() { |
| 25 | dw := DoubleWrapped{ |
| 26 | v: 7 |
| 27 | } |
| 28 | w := Wrapped(dw) |
| 29 | b := Box(w) |
| 30 | assert b.v == 7 |
| 31 | assert dw.v == 7 |
| 32 | } |
| 33 | |
| 34 | fn test_chain_assignment_compat() { |
| 35 | x := AdminId(1) |
| 36 | mut y := Id(0) |
| 37 | y = Id(x) |
| 38 | assert int(y) == 1 |
| 39 | } |
| 40 | |
| 41 | struct Item { |
| 42 | v int |
| 43 | } |
| 44 | |
| 45 | type ItemPair = [2]Item |
| 46 | type ItemPairAlias = ItemPair |
| 47 | |
| 48 | fn test_chain_through_fixed_array_of_non_builtin() { |
| 49 | a := ItemPair([Item{ v: 1 }, Item{ v: 2 }]!) |
| 50 | b := ItemPairAlias(a) |
| 51 | assert b[0].v == 1 |
| 52 | assert b[1].v == 2 |
| 53 | } |
| 54 | |