cgen: fix match struct type cond (#10421)

pull/10424/head
yuyi 2021-06-11 16:58:25 +08:00 committed by GitHub
parent 534b59e721
commit f26626117d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -4254,6 +4254,13 @@ fn (mut g Gen) match_expr_classic(node ast.MatchExpr, is_expr bool, cond_var str
g.write(', ')
g.expr(expr)
g.write(')')
} else if type_sym.kind == .struct_ {
ptr_typ := g.gen_struct_equality_fn(node.cond_type)
g.write('${ptr_typ}_struct_eq(')
g.write(cond_var)
g.write(', ')
g.expr(expr)
g.write(')')
} else if expr is ast.RangeExpr {
// if type is unsigned and low is 0, check is unneeded
mut skip_low := false

View File

@ -1,3 +1,5 @@
struct Foo {}
fn test_match_array_or_map_cond() {
// array
y1 := []byte{}
@ -34,4 +36,14 @@ fn test_match_array_or_map_cond() {
}
println('ret3 is $ret3')
assert ret3
// struct
y4 := Foo{}
x4 := Foo{}
ret4 := match x4 {
y4 { true }
else { false }
}
println('ret4 is $ret4')
assert ret4
}