checker: enable -skip-unused for more examples

pull/8575/head
Delyan Angelov 2021-02-05 11:55:40 +02:00
parent 8f160ee3ed
commit d30f94507c
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 18 additions and 3 deletions

View File

@ -213,6 +213,9 @@ pub fn (mut c Checker) check_files(ast_files []ast.File) {
c.error('a _test.v file should have *at least* one `test_` function', token.Position{})
}
}
if c.pref.skip_unused {
c.mark_used(ast_files)
}
// Make sure fn main is defined in non lib builds
if c.pref.build_mode == .build_module || c.pref.is_test {
return
@ -227,9 +230,6 @@ pub fn (mut c Checker) check_files(ast_files []ast.File) {
} else if !has_main_fn {
c.error('function `main` must be declared in the main module', token.Position{})
}
if c.pref.skip_unused {
c.mark_used(ast_files)
}
}
// do checks specific to files in main module

View File

@ -85,6 +85,21 @@ fn (mut c Checker) mark_used(ast_files []ast.File) {
c.table.used_fns['main.main'] = true
c.table.used_fns['builtin_init'] = true
c.table.used_fns['memdup'] = true
c.table.used_fns['vstring'] = true
c.table.used_fns['vstring_with_len'] = true
c.table.used_fns['string'] = true // array.string
// c.table.used_fns['str'] = true // builtin .str() methods; They use strings.builder and strconv.ftoa_64 etc.
// whitelist common modules const initializers too:
c.table.used_fns['os.getwd'] = true
c.table.used_fns['os.init_os_args'] = true
//
c.table.used_fns['term.can_show_color_on_stdin'] = true
c.table.used_fns['term.can_show_color_on_stdout'] = true
c.table.used_fns['term.can_show_color_on_stderr'] = true
//
c.table.used_fns['main.can_use_relative_paths'] = true
//
// eprintln('>>> c.table.used_fns: $c.table.used_fns')
// c.timing_measure(@FN)
// println(walker.used_fns)