checker: remove vweb unused vars (#8180)

pull/8243/head
Louis Schmieder 2021-01-21 11:09:19 +01:00 committed by GitHub
parent f7c251f8f3
commit 4045ec1ca8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 2 deletions

View File

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

View File

@ -0,0 +1 @@
@test

View File

@ -0,0 +1 @@

View File

@ -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<App>(mut app, 8181)
}

View File

@ -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<TaskDescription>(tasks.len)
mut results := sync.new_channel<TaskDescription>(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 = []
}

View File

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