Skip to content

Commit ddf0468

Browse files
committed
checker: warn on unused imported functions used via import math { sin, cos }
1 parent eb74856 commit ddf0468

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

vlib/v/checker/checker.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,6 +2489,9 @@ fn (mut c Checker) import_stmt(node ast.Import) {
24892489
if !func.is_pub {
24902490
c.error('module `${node.mod}` function `${sym.name}()` is private', sym.pos)
24912491
}
2492+
if func.usages != 1 {
2493+
c.warn('module `${node.mod}` function `${sym.name}()` is unused', sym.pos)
2494+
}
24922495
continue
24932496
}
24942497
if _ := c.file.global_scope.find_const(name) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
vlib/v/checker/tests/import_sym_fn_unused_warning_err.vv:1:15: warning: module `math` function `sin()` is unused
2+
1 | import math { sin, cos }
3+
| ~~~
4+
2 |
5+
3 | fn main() {}
6+
vlib/v/checker/tests/import_sym_fn_unused_warning_err.vv:1:20: warning: module `math` function `cos()` is unused
7+
1 | import math { sin, cos }
8+
| ~~~
9+
2 |
10+
3 | fn main() {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import math { sin, cos }
2+
3+
fn main() {}

0 commit comments

Comments
 (0)