autofree: test returning optionals

pull/11950/head
Alexander Medvednikov 2021-09-23 09:17:53 +03:00
parent b8935551f1
commit 27f5c35bde
2 changed files with 10 additions and 1 deletions

View File

@ -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 }

View File

@ -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
}