mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix autocast in complex if condtions (#18699)
This commit is contained in:
parent
735654296c
commit
2b2aca6eb7
@ -824,6 +824,20 @@ fn (mut c Checker) autocast_in_if_conds(mut right ast.Expr, from_expr ast.Expr,
|
||||
expr_type: from_type
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.autocast_in_if_conds(mut right.expr, from_expr, from_type, to_type)
|
||||
}
|
||||
}
|
||||
ast.ParExpr {
|
||||
c.autocast_in_if_conds(mut right.expr, from_expr, from_type, to_type)
|
||||
}
|
||||
ast.PrefixExpr {
|
||||
c.autocast_in_if_conds(mut right.right, from_expr, from_type, to_type)
|
||||
}
|
||||
ast.CallExpr {
|
||||
c.autocast_in_if_conds(mut right.left, from_expr, from_type, to_type)
|
||||
for mut arg in right.args {
|
||||
c.autocast_in_if_conds(mut arg.expr, from_expr, from_type, to_type)
|
||||
}
|
||||
}
|
||||
ast.InfixExpr {
|
||||
|
32
vlib/v/tests/autocast_in_if_conds_2_test.v
Normal file
32
vlib/v/tests/autocast_in_if_conds_2_test.v
Normal file
@ -0,0 +1,32 @@
|
||||
type MySumType = S1 | S2
|
||||
|
||||
struct Info {
|
||||
name string
|
||||
}
|
||||
|
||||
struct S1 {
|
||||
is_info bool
|
||||
info Info
|
||||
}
|
||||
|
||||
struct S2 {
|
||||
field2 string
|
||||
}
|
||||
|
||||
fn get_name(name string) string {
|
||||
return name
|
||||
}
|
||||
|
||||
fn test_autocast_in_if_conds() {
|
||||
s := MySumType(S1{
|
||||
is_info: false
|
||||
info: Info{'foo'}
|
||||
})
|
||||
|
||||
if s is S1 && !s.is_info && get_name(s.info.name) == 'foo' {
|
||||
println('ok')
|
||||
assert true
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user