diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 497ef43235..254d3638ff 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -213,6 +213,7 @@ pub: is_builtin bool // this function is defined in builtin/strconv ctdefine string // has [if myflag] tag pos token.Position + body_pos token.Position file string pub mut: return_type table.Type diff --git a/vlib/v/gen/fn.v b/vlib/v/gen/fn.v index d272294e04..0224764c80 100644 --- a/vlib/v/gen/fn.v +++ b/vlib/v/gen/fn.v @@ -161,7 +161,7 @@ fn (mut g Gen) gen_fn_decl(it ast.FnDecl) { // //////////// if g.autofree { // println('\n\ncalling free for fn $it.name') - g.free_scope_vars(it.pos.pos + it.pos.len/2) + g.free_scope_vars(it.body_pos.pos) } // ///////// if is_main { diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index c0b5309b28..cd028fc836 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -231,6 +231,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { // Body mut stmts := []ast.Stmt{} no_body := p.tok.kind != .lcbr + body_start_pos := p.peek_tok.position() if p.tok.kind == .lcbr { stmts = p.parse_block_no_scope() } @@ -255,7 +256,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl { is_js: is_js no_body: no_body pos: start_pos.extend(end_pos) - file: p.file_name + body_pos: body_start_pos is_builtin: p.builtin_mod || p.mod in util.builtin_module_parts ctdefine: ctdefine } @@ -306,7 +307,6 @@ fn (mut p Parser) anon_fn() ast.AnonFn { is_anon: true no_body: no_body pos: pos - file: p.file_name } typ: typ }