diff --git a/vlib/v/parser/module.v b/vlib/v/parser/module.v index 86948f8d95d971..0ab553dff22e1d 100644 --- a/vlib/v/parser/module.v +++ b/vlib/v/parser/module.v @@ -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) } diff --git a/vlib/v/parser/tests/import_alias_selective_fn_used.out b/vlib/v/parser/tests/import_alias_selective_fn_used.out new file mode 100644 index 00000000000000..e69de29bb2d1d6 diff --git a/vlib/v/parser/tests/import_alias_selective_fn_used.vv b/vlib/v/parser/tests/import_alias_selective_fn_used.vv new file mode 100644 index 00000000000000..7d68eb9e454d12 --- /dev/null +++ b/vlib/v/parser/tests/import_alias_selective_fn_used.vv @@ -0,0 +1,3 @@ +import os as vos { execute } + +execute('ls') diff --git a/vlib/v/parser/tests/import_alias_selective_symbol_used.out b/vlib/v/parser/tests/import_alias_selective_symbol_used.out new file mode 100644 index 00000000000000..a76273e0e76928 --- /dev/null +++ b/vlib/v/parser/tests/import_alias_selective_symbol_used.out @@ -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{} + | ~~ diff --git a/vlib/v/parser/tests/import_alias_selective_symbol_used.vv b/vlib/v/parser/tests/import_alias_selective_symbol_used.vv new file mode 100644 index 00000000000000..03272b06d951eb --- /dev/null +++ b/vlib/v/parser/tests/import_alias_selective_symbol_used.vv @@ -0,0 +1,3 @@ +import os as vos { Result } + +os := Result{}