Skip to content

Commit

Permalink
parser: register selective import aliases as used (#21613)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored May 31, 2024
1 parent 52dfef1 commit 5657e28
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vlib/v/parser/module.v
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ fn (mut p Parser) register_used_import(alias string) {

fn (mut p Parser) register_used_import_for_symbol_name(sym_name string) {
short_import_name := sym_name.all_before_last('.').all_after_last('.')
for alias, mod in p.imports {
if mod == short_import_name {
p.register_used_import(alias)
return
}
}
p.register_used_import(short_import_name)
}

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions vlib/v/parser/tests/import_alias_selective_fn_used.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os as vos { execute }

execute('ls')
5 changes: 5 additions & 0 deletions vlib/v/parser/tests/import_alias_selective_symbol_used.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vlib/v/parser/tests/import_alias_selective_symbol_used.vv:3:1: warning: unused variable: `os`
1 | import os as vos { Result }
2 |
3 | os := Result{}
| ~~
3 changes: 3 additions & 0 deletions vlib/v/parser/tests/import_alias_selective_symbol_used.vv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os as vos { Result }

os := Result{}

0 comments on commit 5657e28

Please sign in to comment.