mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix fn option-only return print (#17547)
This commit is contained in:
parent
e253256c30
commit
a0b3379d4a
@ -85,7 +85,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
|||||||
} else if typ == ast.bool_type {
|
} else if typ == ast.bool_type {
|
||||||
g.expr(expr)
|
g.expr(expr)
|
||||||
g.write(' ? _SLIT("true") : _SLIT("false")')
|
g.write(' ? _SLIT("true") : _SLIT("false")')
|
||||||
} else if sym.kind == .none_ {
|
} else if sym.kind == .none_ || typ == ast.void_type.set_flag(.option) {
|
||||||
g.write('_SLIT("<none>")')
|
g.write('_SLIT("<none>")')
|
||||||
} else if sym.kind == .enum_ {
|
} else if sym.kind == .enum_ {
|
||||||
if expr !is ast.EnumVal {
|
if expr !is ast.EnumVal {
|
||||||
|
8
vlib/v/tests/option_void_fn_return_test.v
Normal file
8
vlib/v/tests/option_void_fn_return_test.v
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fn foo() ? {
|
||||||
|
return none
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_main() {
|
||||||
|
println(foo()) // <none>
|
||||||
|
assert true
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user