From 13d1d28db152143db703cfc581c38bc09094d23e Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Mon, 24 May 2021 14:42:00 +0300 Subject: [PATCH] v.parser: fix -autofree for script mode programs that do not have explicit `fn main(){}` --- vlib/v/parser/parser.v | 2 ++ vlib/v/tests/valgrind/simple_interpolation.v | 5 +++++ vlib/v/tests/valgrind/simple_interpolation_script_mode.v | 5 +++++ .../simple_interpolation_script_mode_more_scopes.v | 7 +++++++ vlib/v/tests/valgrind/valgrind_test.v | 2 ++ 5 files changed, 21 insertions(+) create mode 100644 vlib/v/tests/valgrind/simple_interpolation.v create mode 100644 vlib/v/tests/valgrind/simple_interpolation_script_mode.v create mode 100644 vlib/v/tests/valgrind/simple_interpolation_script_mode_more_scopes.v diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 137ae83358..371dee48f3 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -575,10 +575,12 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { else { p.inside_fn = true if p.pref.is_script && !p.pref.is_test { + p.open_scope() mut stmts := []ast.Stmt{} for p.tok.kind != .eof { stmts << p.stmt(false) } + p.close_scope() return ast.FnDecl{ name: 'main.main' mod: 'main' diff --git a/vlib/v/tests/valgrind/simple_interpolation.v b/vlib/v/tests/valgrind/simple_interpolation.v new file mode 100644 index 0000000000..16acab5b0b --- /dev/null +++ b/vlib/v/tests/valgrind/simple_interpolation.v @@ -0,0 +1,5 @@ +fn main() { + v := 't' + s := '${v}.tmp' + println(s) +} diff --git a/vlib/v/tests/valgrind/simple_interpolation_script_mode.v b/vlib/v/tests/valgrind/simple_interpolation_script_mode.v new file mode 100644 index 0000000000..9090ae79cb --- /dev/null +++ b/vlib/v/tests/valgrind/simple_interpolation_script_mode.v @@ -0,0 +1,5 @@ +v := 't' + +s := '${v}.tmp' + +println(s) diff --git a/vlib/v/tests/valgrind/simple_interpolation_script_mode_more_scopes.v b/vlib/v/tests/valgrind/simple_interpolation_script_mode_more_scopes.v new file mode 100644 index 0000000000..085664613e --- /dev/null +++ b/vlib/v/tests/valgrind/simple_interpolation_script_mode_more_scopes.v @@ -0,0 +1,7 @@ +{ + { + v := 't' + s := '${v}.tmp' + println(s) + } +} diff --git a/vlib/v/tests/valgrind/valgrind_test.v b/vlib/v/tests/valgrind/valgrind_test.v index 7529568868..0f9f5f5eca 100644 --- a/vlib/v/tests/valgrind/valgrind_test.v +++ b/vlib/v/tests/valgrind/valgrind_test.v @@ -78,6 +78,7 @@ fn test_all() { bench.fail() eprintln(bench.step_message_fail('file: $test could not be compiled.')) eprintln(res.output) + eprintln('You can reproduce the failure with:\n$compile_cmd') continue } if test in skip_valgrind_files { @@ -94,6 +95,7 @@ fn test_all() { bench.fail() eprintln(bench.step_message_fail('failed valgrind check for ${util.bold(test)}')) eprintln(valgrind_res.output) + eprintln('You can reproduce the failure with:\n$compile_cmd && $valgrind_cmd') continue } bench.ok()