1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix comptime checking optional type with IS operator (#16688)

This commit is contained in:
Felipe Pena
2022-12-16 10:53:04 -03:00
committed by GitHub
parent f0a252d0e6
commit 65a020e385
3 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1 @@
202201

View File

@ -0,0 +1,17 @@
module main
struct Foo {
a string
b ?string
}
fn test_main() {
$for field in Foo.fields {
print(field.typ)
$if field.typ is ?string {
print(1)
} $else $if field.typ is string {
print(2)
}
}
}

View File

@ -434,7 +434,7 @@ fn (mut g Gen) comptime_if_cond(cond ast.Expr, pkg_exist bool) bool {
}
if cond.op == .key_is {
g.write('${exp_type.idx()} == ${got_type.idx()}')
g.write('${exp_type.idx()} == ${got_type.idx()} && ${exp_type.has_flag(.optional)} == ${got_type.has_flag(.optional)}')
return exp_type == got_type
} else {
g.write('${exp_type.idx()} != ${got_type.idx()}')