diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 947fb207e2..51de44c72a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -73,6 +73,7 @@ mut: loop_label string // set when inside a labelled for loop timers &util.Timers = util.new_timers(false) comptime_fields_type map[string]table.Type + fn_scope &ast.Scope = voidptr(0) } pub fn new_checker(table &table.Table, pref &pref.Preferences) Checker { @@ -3584,6 +3585,19 @@ fn (mut c Checker) comptime_call(mut node ast.ComptimeCall) table.Type { } mut c2 := new_checker(c.table, pref2) c2.check(node.vweb_tmpl) + mut i := 0 // tmp counter var for skipping first three tmpl vars + for k, _ in c2.file.scope.children[0].objects { + if i < 4 { + // Skip first three because they are tmpl vars see vlib/vweb/tmpl/tmpl.v + i++ + continue + } + if k in c.fn_scope.objects && c.fn_scope.objects[k] is ast.Var { + mut vsc := c.fn_scope.objects[k] as ast.Var + vsc.is_used = true + c.fn_scope.objects[k] = vsc + } + } c.warnings << c2.warnings c.errors << c2.errors c.nr_warnings += c2.nr_warnings @@ -5319,6 +5333,7 @@ fn (mut c Checker) fn_decl(mut node ast.FnDecl) { } } } + c.fn_scope = node.scope c.stmts(node.stmts) returns := c.returns || has_top_return(node.stmts) if node.language == .v && !node.no_body && node.return_type != table.void_type && !returns && diff --git a/vlib/v/checker/tests/templates/index.html b/vlib/v/checker/tests/templates/index.html new file mode 100644 index 0000000000..7624de14f1 --- /dev/null +++ b/vlib/v/checker/tests/templates/index.html @@ -0,0 +1 @@ +@test diff --git a/vlib/v/checker/tests/vweb_tmpl_used_var.out b/vlib/v/checker/tests/vweb_tmpl_used_var.out new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/vlib/v/checker/tests/vweb_tmpl_used_var.out @@ -0,0 +1 @@ + diff --git a/vlib/v/checker/tests/vweb_tmpl_used_var.vv b/vlib/v/checker/tests/vweb_tmpl_used_var.vv new file mode 100644 index 0000000000..636f745375 --- /dev/null +++ b/vlib/v/checker/tests/vweb_tmpl_used_var.vv @@ -0,0 +1,15 @@ +import vweb + +struct App { + vweb.Context +} + +pub fn (mut app App) index() vweb.Result { + test := 'test' + return $vweb.html() +} + +fn main() { + mut app := App{} + vweb.run_app(mut app, 8181) +} diff --git a/vlib/v/compiler_errors_test.v b/vlib/v/compiler_errors_test.v index 699dde33c1..df679035e5 100644 --- a/vlib/v/compiler_errors_test.v +++ b/vlib/v/compiler_errors_test.v @@ -11,6 +11,10 @@ const skip_files = [ 'vlib/v/checker/tests/custom_comptime_define_if_flag.vv', ] +const skip_on_ubuntu_musl = [ + 'vlib/v/checker/tests/vweb_tmpl_used_var.vv', +] + const turn_off_vcolors = os.setenv('VCOLORS', 'never', true) const should_autofix = os.getenv('VAUTOFIX') != '' @@ -89,6 +93,9 @@ fn (mut tasks []TaskDescription) run() { mut work := sync.new_channel(tasks.len) mut results := sync.new_channel(tasks.len) mut m_skip_files := skip_files.clone() + if os.getenv('V_CI_UBUNTU_MUSL').len > 0 { + m_skip_files << skip_on_ubuntu_musl + } $if noskip ? { m_skip_files = [] } diff --git a/vlib/v/parser/comptime.v b/vlib/v/parser/comptime.v index 2e74b296f8..c05a902b44 100644 --- a/vlib/v/parser/comptime.v +++ b/vlib/v/parser/comptime.v @@ -109,9 +109,10 @@ fn (mut p Parser) comp_call() ast.ComptimeCall { fn_path := p.cur_fn_name.split('_') tmpl_path := if is_html { '${fn_path.last()}.html' } else { s } // Looking next to the vweb program - dir := os.dir(p.scanner.file_path) - mut path := os.join_path(dir, fn_path.join('/')) + dir := os.dir(p.scanner.file_path.replace('/', os.path_separator)) + mut path := os.join_path(dir, fn_path.join(os.path_separator)) path += '.html' + path = os.real_path(path) if !is_html { path = tmpl_path }