autofree: optionals fix

pull/6585/head
Alexander Medvednikov 2020-10-09 01:13:25 +02:00
parent 92630a2821
commit c463c26983
3 changed files with 9 additions and 9 deletions

View File

@ -20,3 +20,4 @@
- method expressions with an explicit receiver as the first argument - method expressions with an explicit receiver as the first argument
- fix all remaining generics issues (`foo(5)` instead of `foo<int>(5)` etc) - fix all remaining generics issues (`foo(5)` instead of `foo<int>(5)` etc)
- merge v.c and v_win.c - merge v.c and v_win.c
- more advanced errors, not just `error('message')`

View File

@ -1361,6 +1361,13 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
g.writeln('); // free str on re-assignment') g.writeln('); // free str on re-assignment')
} }
} }
// Autofree tmp arg vars
first_right := assign_stmt.right[0]
af := g.pref.autofree && first_right is ast.CallExpr && !g.is_builtin_mod
if af {
g.autofree_call_pregen(first_right as ast.CallExpr)
}
//
// Handle optionals. We need to declare a temp variable for them, that's why they are handled // Handle optionals. We need to declare a temp variable for them, that's why they are handled
// here, not in call_expr(). // here, not in call_expr().
// `pos := s.index('x') or { return }` // `pos := s.index('x') or { return }`
@ -1388,13 +1395,6 @@ fn (mut g Gen) gen_assign_stmt(assign_stmt ast.AssignStmt) {
// return // return
} }
} }
// Autofree tmp arg vars
first_right := assign_stmt.right[0]
af := g.pref.autofree && first_right is ast.CallExpr && !g.is_builtin_mod
if af {
g.autofree_call_pregen(first_right as ast.CallExpr)
}
//
// json_test failed w/o this check // json_test failed w/o this check
if return_type != table.void_type && return_type != 0 { if return_type != table.void_type && return_type != 0 {
sym := g.table.get_type_symbol(return_type) sym := g.table.get_type_symbol(return_type)

View File

@ -91,7 +91,6 @@ fn opt(s string) ?int {
return 1 return 1
} }
/*
fn optional_str() { fn optional_str() {
q := 'select' q := 'select'
s := 'query: select' s := 'query: select'
@ -109,7 +108,7 @@ fn optional_str() {
} }
println(pos + 1) println(pos + 1)
} }
*/
fn tt() { fn tt() {
// time.parse_rfc2822('1234') // time.parse_rfc2822('1234')
} }