1
0
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:
Felipe Pena 2023-03-08 16:53:23 -03:00 committed by GitHub
parent e253256c30
commit a0b3379d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -85,7 +85,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
} else if typ == ast.bool_type {
g.expr(expr)
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>")')
} else if sym.kind == .enum_ {
if expr !is ast.EnumVal {

View File

@ -0,0 +1,8 @@
fn foo() ? {
return none
}
fn test_main() {
println(foo()) // <none>
assert true
}