mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix sumtype with none
(#14965)
This commit is contained in:
parent
d86b4951c7
commit
f4b39fbe4f
@ -2078,7 +2078,11 @@ fn (mut g Gen) call_cfn_for_casting_expr(fname string, expr ast.Expr, exp_is_ptr
|
|||||||
g.write('&')
|
g.write('&')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if got_styp == 'none' && !g.cur_fn.return_type.has_flag(.optional) {
|
||||||
|
g.write('(none){EMPTY_STRUCT_INITIALIZATION}')
|
||||||
|
} else {
|
||||||
g.expr(expr)
|
g.expr(expr)
|
||||||
|
}
|
||||||
g.write(')'.repeat(rparen_n))
|
g.write(')'.repeat(rparen_n))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
18
vlib/v/tests/sumtype_with_none_test.v
Normal file
18
vlib/v/tests/sumtype_with_none_test.v
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
module main
|
||||||
|
|
||||||
|
fn string_none() string | none {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_sumtype_with_none() {
|
||||||
|
x := string_none()
|
||||||
|
res := match x {
|
||||||
|
string {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
none {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert res
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user