From 27f5c35bdeff3a33f02ef596e27252d60497299e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 23 Sep 2021 09:17:53 +0300 Subject: [PATCH] autofree: test returning optionals --- vlib/v/gen/c/cgen.v | 2 +- vlib/v/tests/valgrind/1.strings_and_arrays.v | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index a5a48fcb77..9e4ffa7cac 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -3619,7 +3619,7 @@ fn (mut g Gen) expr(node ast.Expr) { g.error('unknown type `$sym.name`', node.pos) } styp := g.typ(node_typ) - g.write('/*SizeOf*/ sizeof(${util.no_dots(styp)})') + g.write('sizeof(${util.no_dots(styp)})') } ast.IsRefType { typ := if node.typ == g.field_data_type { g.comp_for_field_value.typ } else { node.typ } diff --git a/vlib/v/tests/valgrind/1.strings_and_arrays.v b/vlib/v/tests/valgrind/1.strings_and_arrays.v index 1802eb2722..8d24f4e110 100644 --- a/vlib/v/tests/valgrind/1.strings_and_arrays.v +++ b/vlib/v/tests/valgrind/1.strings_and_arrays.v @@ -25,6 +25,15 @@ fn return_array(array_arg []string) []int { // array argument must not be freed return s } +fn return_option(array_arg []string) ?Foo { // array argument must not be freed + s := get_foo() ? // escaping option must not be freed + return s +} + +fn get_foo() ?Foo { + return Foo{} +} + fn handle_strings(s string, p string) int { return 0 }