Skip to content

Commit

Permalink
checker: warn on unused imported functions used via `import math { si…
Browse files Browse the repository at this point in the history
…n, cos }`
  • Loading branch information
Delta456 committed Nov 2, 2023
1 parent eb74856 commit ddf0468
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/checker/checker.v
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,9 @@ fn (mut c Checker) import_stmt(node ast.Import) {
if !func.is_pub {
c.error('module `${node.mod}` function `${sym.name}()` is private', sym.pos)
}
if func.usages != 1 {
c.warn('module `${node.mod}` function `${sym.name}()` is unused', sym.pos)
}
continue
}
if _ := c.file.global_scope.find_const(name) {
Expand Down
10 changes: 10 additions & 0 deletions vlib/v/checker/tests/import_sym_fn_unused_warning_err.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
vlib/v/checker/tests/import_sym_fn_unused_warning_err.vv:1:15: warning: module `math` function `sin()` is unused
1 | import math { sin, cos }
| ~~~
2 |
3 | fn main() {}
vlib/v/checker/tests/import_sym_fn_unused_warning_err.vv:1:20: warning: module `math` function `cos()` is unused
1 | import math { sin, cos }
| ~~~
2 |
3 | fn main() {}
3 changes: 3 additions & 0 deletions vlib/v/checker/tests/import_sym_fn_unused_warning_err.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import math { sin, cos }

fn main() {}

0 comments on commit ddf0468

Please sign in to comment.