checker: fix -skip-unused with struct inits with default expressions
parent
eb7009b60a
commit
4646c414d8
|
@ -131,6 +131,7 @@ fn (mut c Checker) mark_used(ast_files []ast.File) {
|
|||
}
|
||||
|
||||
mut walker := mark_used_walker.Walker{
|
||||
table: c.table
|
||||
files: ast_files
|
||||
all_fns: all_fns
|
||||
all_consts: all_consts
|
||||
|
|
|
@ -5,9 +5,11 @@ module mark_used_walker
|
|||
// This module walks the entire program starting at fn main and marks used (called) functions.
|
||||
// Unused functions can be safely skipped by the backends to save CPU time and space.
|
||||
import v.ast
|
||||
import v.table
|
||||
|
||||
pub struct Walker {
|
||||
pub mut:
|
||||
table &table.Table
|
||||
used_fns map[string]bool // used_fns['println'] == true
|
||||
used_consts map[string]bool // used_consts['os.args'] == true
|
||||
n_maps int
|
||||
|
@ -258,8 +260,19 @@ fn (mut w Walker) expr(node ast.Expr) {
|
|||
w.expr(node.where_expr)
|
||||
}
|
||||
ast.StructInit {
|
||||
// eprintln('>>>> ast.StructInit: $node')
|
||||
w.expr(node.update_expr)
|
||||
sym := w.table.get_type_symbol(node.typ)
|
||||
if sym.kind == .struct_ {
|
||||
info := sym.info as table.Struct
|
||||
for ifield in info.fields {
|
||||
if ifield.has_default_expr {
|
||||
defex := ast.fe2ex(ifield.default_expr)
|
||||
w.expr(defex)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.has_update_expr {
|
||||
w.expr(node.update_expr)
|
||||
}
|
||||
for sif in node.fields {
|
||||
w.expr(sif.expr)
|
||||
}
|
||||
|
@ -321,13 +334,13 @@ pub fn (mut w Walker) fn_decl(mut node ast.FnDecl) {
|
|||
}
|
||||
|
||||
pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
|
||||
for arg in node.args {
|
||||
w.expr(arg.expr)
|
||||
}
|
||||
if node.language == .c {
|
||||
return
|
||||
}
|
||||
w.expr(node.left)
|
||||
for arg in node.args {
|
||||
w.expr(arg.expr)
|
||||
}
|
||||
w.or_block(node.or_block)
|
||||
//
|
||||
fn_name := if node.is_method { node.receiver_type.str() + '.' + node.name } else { node.name }
|
||||
|
|
Loading…
Reference in New Issue