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:
@ -0,0 +1 @@
|
||||
202201
|
17
vlib/v/checker/tests/comptime_if_optional_string_test.vv
Normal file
17
vlib/v/checker/tests/comptime_if_optional_string_test.vv
Normal 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)
|
||||
}
|
||||
}
|
||||
}
|
@ -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()}')
|
||||
|
Reference in New Issue
Block a user