From a44a03f9a5b8c6936ec449c7b5887176be53950b Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 24 Sep 2019 13:18:06 +1000 Subject: [PATCH] compiler: fix mark_var_used() --- compiler/fn.v | 2 +- compiler/parser.v | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/fn.v b/compiler/fn.v index e443c8600f..82c2bc045d 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -69,7 +69,7 @@ fn (p mut Parser) open_scope() { } fn (p mut Parser) mark_var_used(v Var) { - if v.idx == -1 { + if v.idx == -1 || v.idx >= p.local_vars.len { return } p.local_vars[v.idx].is_used = true diff --git a/compiler/parser.v b/compiler/parser.v index 0da1a7f3ce..dd57615d40 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -276,10 +276,10 @@ fn (p mut Parser) parse(pass Pass) { p.cgen.consts << g case Token.eof: //p.log('end of parse()') - if p.is_script && !p.pref.is_test { - p.set_current_fn( MainFn ) - p.check_unused_variables() - } + // if p.is_script && !p.pref.is_test { + // p.set_current_fn( MainFn ) + // p.check_unused_variables() + // } if !p.first_pass() && !p.pref.is_repl { p.check_unused_imports() }