Skip to content

Commit 565e6ef

Browse files
authored
markused: fix fn marked as used when variable and fn uses same name (fix #25649) (#25650)
1 parent 7a14eb0 commit 565e6ef

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

vlib/v/markused/walker.v

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,11 @@ fn (mut w Walker) expr(node_ ast.Expr) {
728728
} else if node.name in w.all_globals {
729729
w.mark_global_as_used(node.name)
730730
} else {
731-
w.fn_by_name(node.name)
731+
if (node.kind == .variable && node.obj is ast.Var && node.obj.is_used
732+
&& node.obj.typ != 0 && w.table.type_kind(node.obj.typ) == .function)
733+
|| (node.kind == .unresolved && node.name.contains('.')) {
734+
w.fn_by_name(node.name)
735+
}
732736
}
733737
if !w.uses_atomic && node.info is ast.IdentVar {
734738
w.uses_atomic = node.info.typ.has_flag(.atomic_f)

vlib/v/tests/skip_unused/for_linked_list.run.out

Whitespace-only changes.

vlib/v/tests/skip_unused/for_linked_list.skip_unused.run.out

Whitespace-only changes.
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
struct Node {
2+
mut:
3+
value int
4+
prev ?&Node
5+
next ?&Node
6+
}
7+
8+
struct LinkedList {
9+
mut:
10+
length int
11+
head ?&Node
12+
}
13+
14+
pub fn (mut l LinkedList) push(value int) {
15+
mut new_node := &Node{
16+
value: value
17+
}
18+
19+
if mut head := l.head {
20+
for head.next != none {
21+
if mut head_next := head.next {
22+
head = head_next
23+
}
24+
}
25+
head.next = new_node
26+
new_node.prev = head
27+
} else {
28+
l.head = new_node
29+
}
30+
}
31+
32+
fn main() {
33+
mut list := LinkedList{
34+
length: 0
35+
head: none
36+
}
37+
list.push(1)
38+
list.push(2)
39+
list.push(3)
40+
}

0 commit comments

Comments
 (0)