diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index f1634392f2..7ba552c364 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -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 diff --git a/vlib/v/tests/comptime_if_is_test.v b/vlib/v/tests/comptime_if_is_test.v index 8b63433fb8..e0bf7e937d 100644 --- a/vlib/v/tests/comptime_if_is_test.v +++ b/vlib/v/tests/comptime_if_is_test.v @@ -13,3 +13,17 @@ fn test_generic_is() { assert f() == 1 assert f() == -1 } + +fn g(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 +} +