cgen: auto dereference for optional

pull/4631/head
joe-conigliaro 2020-04-28 15:59:41 +10:00
parent 28f5920bb0
commit ef4f4825ac
1 changed files with 4 additions and 0 deletions

View File

@ -1902,6 +1902,10 @@ fn (mut g Gen) return_statement(node ast.Return) {
if !is_none && !is_error { if !is_none && !is_error {
styp := g.base_typ(g.fn_decl.return_type) styp := g.base_typ(g.fn_decl.return_type)
g.write('/*:)$return_sym.name*/opt_ok(&($styp[]) { ') g.write('/*:)$return_sym.name*/opt_ok(&($styp[]) { ')
if !g.fn_decl.return_type.is_ptr() && node.types[0].is_ptr() {
// Automatic Dereference for optional
g.write('*')
}
g.expr(node.exprs[0]) g.expr(node.exprs[0])
g.writeln(' }, sizeof($styp));') g.writeln(' }, sizeof($styp));')
return return