gen: fix generating `$if expr || expr` (#9270)

pull/9285/head
Nick Treleaven 2021-03-13 06:45:50 +00:00 committed by GitHub
parent fecf4a6f58
commit c06e58d418
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -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
}