Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v: fix -skip-unused error with aggregate method call #22883

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions vlib/v/markused/walker.v
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,17 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
}
return
}
if node.is_method && node.left_type != 0 {
left_sym := w.table.sym(node.left_type)
if left_sym.info is ast.Aggregate {
for types in left_sym.info.types {
fn_name := '${types.idx()}.${node.name}'
if !w.used_fns[fn_name] {
w.mark_aggregate_call_used(fn_name, types)
}
}
}
}
w.expr(node.left)
w.or_block(node.or_block)

Expand Down Expand Up @@ -566,6 +577,16 @@ pub fn (mut w Walker) call_expr(mut node ast.CallExpr) {
}
}

// visit aggregate type method declaration
pub fn (mut w Walker) mark_aggregate_call_used(fn_name string, left_type ast.Type) {
if w.used_fns[fn_name] {
return
}
w.mark_fn_as_used(fn_name)
stmt := w.all_fns[fn_name] or { return }
w.stmts(stmt.stmts)
}

pub fn (mut w Walker) fn_by_name(fn_name string) {
if w.used_fns[fn_name] {
return
Expand Down
Loading