1
0
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:
Nick Treleaven 2021-01-25 13:25:52 +00:00 committed by GitHub
parent b2f2f387dc
commit 02d8ede94d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -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 // this is only allowed for generics currently, otherwise blocked by checker
exp_type = g.unwrap_generic(left.typ) 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 { .eq, .ne {
// TODO Implement `$if method.args.len == 1` // TODO Implement `$if method.args.len == 1`

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