mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
gen: fix generating $if expr || expr
(#9270)
This commit is contained in:
parent
fecf4a6f58
commit
c06e58d418
@ -286,7 +286,7 @@ fn (mut g Gen) comp_if_cond(cond ast.Expr) bool {
|
||||
l := g.comp_if_cond(cond.left)
|
||||
g.write(' $cond.op ')
|
||||
r := g.comp_if_cond(cond.right)
|
||||
return l && r
|
||||
return if cond.op == .and { l && r } else { l || r }
|
||||
}
|
||||
.key_is, .not_is {
|
||||
left := cond.left
|
||||
|
@ -13,3 +13,17 @@ fn test_generic_is() {
|
||||
assert f<int>() == 1
|
||||
assert f<bool>() == -1
|
||||
}
|
||||
|
||||
fn g<T>(t T) int {
|
||||
$if T is byte || T is i8 {
|
||||
return 1
|
||||
}
|
||||
return 2
|
||||
}
|
||||
|
||||
fn test_is_or() {
|
||||
assert g(byte(1)) == 1
|
||||
assert g(i8(1)) == 1
|
||||
assert g(1) == 2
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user