autofree: another lambda fix

pull/6698/head
Alexander Medvednikov 2020-10-30 00:43:04 +01:00
parent ccc0cb23ed
commit dca3d13606
3 changed files with 6 additions and 4 deletions

View File

@ -2018,13 +2018,14 @@ fn (mut g Gen) expr(node ast.Expr) {
// if g.fileis('1.strings') {
// println('before:' + node.autofree_pregen)
// }
if g.pref.autofree && !g.is_builtin_mod && g.strs_to_free0.len == 0 && !g.inside_lambda { // && g.inside_ternary ==
if g.pref.autofree && !g.is_builtin_mod && !g.is_js_call && g.strs_to_free0.len ==
0 && !g.inside_lambda { // && g.inside_ternary ==
// if len != 0, that means we are handling call expr inside call expr (arg)
// and it'll get messed up here, since it's handled recursively in autofree_call_pregen()
// so just skip it
g.autofree_call_pregen(node)
if g.strs_to_free0.len > 0 {
g.insert_before_stmt(g.strs_to_free0.join('\n'))
g.insert_before_stmt(g.strs_to_free0.join('\n') + '/* inserted before */')
}
g.strs_to_free0 = []
// println('pos=$node.pos.pos')

View File

@ -438,7 +438,7 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
} else if !node.receiver_type.is_ptr() && node.left_type.is_ptr() && node.name != 'str' {
g.write('/*rec*/*')
}
if node.free_receiver {
if node.free_receiver && !g.inside_lambda {
// The receiver expression needs to be freed, use the temp var.
fn_name := node.name.replace('.', '_')
arg_name := '_arg_expr_${fn_name}_0_$node.pos.pos'

View File

@ -359,7 +359,8 @@ fn handle_conn<T>(conn net.Socket, mut app T) {
} else {
// Parse URL query
if url_words.last().contains('?') {
tmp_query := url_words.last().all_after('?').split('&').map(it.split('='))
words := url_words.last().after('?').split('&')
tmp_query := words.map(it.split('='))
url_words[url_words.len - 1] = url_words.last().all_before('?')
for data in tmp_query {
if data.len == 2 {