1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v.parser: fix -autofree for script mode programs that do not have explicit fn main(){}

This commit is contained in:
Delyan Angelov 2021-05-24 14:42:00 +03:00
parent ce7f78522d
commit 13d1d28db1
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
5 changed files with 21 additions and 0 deletions

View File

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

View File

@ -0,0 +1,5 @@
fn main() {
v := 't'
s := '${v}.tmp'
println(s)
}

View File

@ -0,0 +1,5 @@
v := 't'
s := '${v}.tmp'
println(s)

View File

@ -0,0 +1,7 @@
{
{
v := 't'
s := '${v}.tmp'
println(s)
}
}

View File

@ -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()