checker: fix error for match sumtype that referenced before (#14338)
parent
106487d62f
commit
8519996201
|
@ -3656,6 +3656,7 @@ pub fn (mut c Checker) mark_as_referenced(mut node ast.Expr, as_interface bool)
|
|||
node.obj.is_auto_heap = true
|
||||
}
|
||||
}
|
||||
.sum_type, .interface_ {}
|
||||
else {
|
||||
node.obj.is_auto_heap = true
|
||||
}
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
struct Player {
|
||||
mut:
|
||||
x int
|
||||
y int
|
||||
level int
|
||||
}
|
||||
|
||||
struct Enemy {
|
||||
mut:
|
||||
x int
|
||||
y int
|
||||
damage f64
|
||||
}
|
||||
|
||||
type PlayerOrEnemy = Enemy | Player
|
||||
|
||||
fn test_match_reference_sumtype_var() {
|
||||
mut entity := PlayerOrEnemy(Player{10, 12, 3})
|
||||
|
||||
x_move := 11
|
||||
y_move := 22
|
||||
|
||||
mut ref := &entity
|
||||
|
||||
match mut entity {
|
||||
Player {
|
||||
entity.x += x_move
|
||||
entity.y += y_move
|
||||
|
||||
println('Player is moved to $entity.x, $entity.y and its level is $entity.level')
|
||||
}
|
||||
Enemy {
|
||||
entity.x += x_move
|
||||
entity.y += y_move
|
||||
|
||||
println('Enemy is moved to $entity.x, $entity.y and its damage is $entity.damage')
|
||||
}
|
||||
}
|
||||
|
||||
println(typeof(ref).name)
|
||||
assert true
|
||||
}
|
Loading…
Reference in New Issue