diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 33848515fa..b3182d26e8 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -195,7 +195,7 @@ fn (mut c Checker) check_file_in_main(file ast.File) bool { } fn (mut c Checker) check_valid_snake_case(name, identifier string, pos token.Position) { - if name[0] == `_` { + if name[0] == `_` && !c.pref.is_vweb { c.error('$identifier `$name` cannot start with `_`', pos) } if util.contains_capital(name) { @@ -1765,14 +1765,14 @@ pub fn (c &Checker) unwrap_generic(typ table.Type) table.Type { // TODO node must be mut pub fn (mut c Checker) expr(node ast.Expr) table.Type { - c.expr_level++ - defer { c.expr_level -- } + defer { + c.expr_level-- + } if c.expr_level > 200 { c.error('checker: too many expr levels: $c.expr_level ', node.position()) return table.void_type } - match mut node { ast.AnonFn { keep_fn := c.cur_fn @@ -1851,7 +1851,12 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type { ast.ComptimeCall { it.sym = c.table.get_type_symbol(c.unwrap_generic(c.expr(it.left))) if it.is_vweb { - mut c2 := new_checker(c.table, c.pref) + x := *c.pref + xx := { + x | + is_vweb: true + } // TODO assoc parser bug + mut c2 := new_checker(c.table, xx) c2.check(it.vweb_tmpl) c.warnings << c2.warnings c.errors << c2.errors @@ -1953,7 +1958,8 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type { if !c.check_types(ltype, table.bool_type) { ltype_sym := c.table.get_type_symbol(ltype) lname := if it.is_likely { '_likely_' } else { '_unlikely_' } - c.error('`${lname}()` expects a boolean expression, instead it got `${ltype_sym.name}`', it.pos) + c.error('`${lname}()` expects a boolean expression, instead it got `${ltype_sym.name}`', + it.pos) } return table.bool_type } diff --git a/vlib/v/gen/comptime.v b/vlib/v/gen/comptime.v index f9c4a32af8..c40114437f 100644 --- a/vlib/v/gen/comptime.v +++ b/vlib/v/gen/comptime.v @@ -18,7 +18,7 @@ fn (g &Gen) comptime_call(node ast.ComptimeCall) { } } } - g.writeln('vweb__Context_html(&app->vweb, tmpl_res_$g.fn_decl.name)') + g.writeln('vweb__Context_html(&app->vweb, _tmpl_res_$g.fn_decl.name)') return } g.writeln('// $' + 'method call. sym="$node.sym.name"') diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index b6532d50d6..2e1140c4db 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -112,6 +112,7 @@ pub mut: use_color ColorOutput // whether the warnings/errors should use ANSI color escapes. is_parallel bool error_limit int + is_vweb bool // skip _ var warning in templates } pub fn parse_args(args []string) (&Preferences, string) { diff --git a/vlib/vweb/tmpl/tmpl.v b/vlib/vweb/tmpl/tmpl.v index af3d71fab6..d9e7367be0 100644 --- a/vlib/vweb/tmpl/tmpl.v +++ b/vlib/vweb/tmpl/tmpl.v @@ -113,7 +113,7 @@ pub fn compile_template(content, fn_name string) string { } } s.writeln(str_end) - s.writeln('tmpl_res_$fn_name := sb.str() ') + s.writeln('_tmpl_res_$fn_name := sb.str() ') s.writeln('}') s.writeln('// === end of vweb html template ===') return s.str()