mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix $if T !is
(#8311)
This commit is contained in:
parent
b2f2f387dc
commit
02d8ede94d
@ -268,7 +268,8 @@ fn (mut g Gen) comp_if_expr(cond ast.Expr) {
|
||||
// this is only allowed for generics currently, otherwise blocked by checker
|
||||
exp_type = g.unwrap_generic(left.typ)
|
||||
}
|
||||
g.write('$exp_type == $got_type')
|
||||
op := if cond.op == .key_is { '==' } else { '!=' }
|
||||
g.write('$exp_type $op $got_type')
|
||||
}
|
||||
.eq, .ne {
|
||||
// TODO Implement `$if method.args.len == 1`
|
||||
|
15
vlib/v/tests/comptime_if_is_test.v
Normal file
15
vlib/v/tests/comptime_if_is_test.v
Normal file
@ -0,0 +1,15 @@
|
||||
fn f<T>() int {
|
||||
$if T is int {
|
||||
return 1
|
||||
}
|
||||
$if T !is int {
|
||||
return -1
|
||||
}
|
||||
assert false
|
||||
return 0
|
||||
}
|
||||
|
||||
fn test_generic_is() {
|
||||
assert f<int>() == 1
|
||||
assert f<bool>() == -1
|
||||
}
|
Loading…
Reference in New Issue
Block a user