From ef4f4825ac6aa3c1b2aaad82950a2245a11549f0 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 28 Apr 2020 15:59:41 +1000 Subject: [PATCH] cgen: auto dereference for optional --- vlib/v/gen/cgen.v | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index e2b57d9175..aebac12d51 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1902,6 +1902,10 @@ fn (mut g Gen) return_statement(node ast.Return) { if !is_none && !is_error { styp := g.base_typ(g.fn_decl.return_type) 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.writeln(' }, sizeof($styp));') return