checker: warn on unused imported functions used via import math { sin, cos }

This commit is contained in:
Swastik 2023-11-02 19:50:18 +05:30
parent d5458b58eb
commit a835e24af5
3 changed files with 16 additions and 0 deletions

View file

@ -2843,6 +2843,9 @@ fn (mut c Checker) import_stmt(node ast.Import) {
if !func.is_pub { if !func.is_pub {
c.error('module `${node.mod}` function `${sym.name}()` is private', sym.pos) 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 continue
} }
if _ := c.file.global_scope.find_const(name) { if _ := c.file.global_scope.find_const(name) {

View file

@ -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() {}

View file

@ -0,0 +1,3 @@
import math { sin, cos }
fn main() {}