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

vweb: fix unused var warning

This commit is contained in:
Alexander Medvednikov 2020-06-10 12:17:49 +02:00
parent deddc71720
commit a130d3cd14
4 changed files with 15 additions and 8 deletions

View File

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

View File

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

View File

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

View File

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