From 535b04f4eda37a3119728350ed1f4afb8ac52d99 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Sun, 2 Feb 2025 14:21:17 +0530 Subject: [PATCH] v.parser: prevent unused warning on `import mod { Sym }`, when `Sym` is later used, for more cases (fix #23412) (#23626) --- .../tests/modules/enum_from_string_in_different_mods.out | 7 ------- vlib/v/parser/parser.v | 3 +++ vlib/v/slow_tests/inout/import_sym_field_no_warn.out | 1 + vlib/v/slow_tests/inout/import_sym_field_no_warn.vv | 7 +++++++ 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 vlib/v/slow_tests/inout/import_sym_field_no_warn.out create mode 100644 vlib/v/slow_tests/inout/import_sym_field_no_warn.vv diff --git a/vlib/v/checker/tests/modules/enum_from_string_in_different_mods.out b/vlib/v/checker/tests/modules/enum_from_string_in_different_mods.out index e597eb825..9a5cc8986 100644 --- a/vlib/v/checker/tests/modules/enum_from_string_in_different_mods.out +++ b/vlib/v/checker/tests/modules/enum_from_string_in_different_mods.out @@ -1,10 +1,3 @@ -vlib/v/checker/tests/modules/enum_from_string_in_different_mods/src/main.v:3:8: warning: module 'mod' is imported but never used - 1 | module main - 2 | - 3 | import mod { MyEnum, MyStruct } - | ~~~ - 4 | - 5 | fn main() { vlib/v/checker/tests/modules/enum_from_string_in_different_mods/src/main.v:3:14: error: module `mod` type `MyEnum` is private 1 | module main 2 | diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d3d9b6553..0ddfb0e03 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -747,6 +747,9 @@ fn (mut p Parser) check_name() string { name := p.tok.lit if p.tok.kind != .name && p.peek_tok.kind == .dot && name in p.imports { p.register_used_import(name) + } else if p.tok.kind == .name && p.peek_tok.kind == .dot && name in p.imported_symbols { + // symbols like Enum.field_name + p.register_used_import_for_symbol_name(p.imported_symbols[name]) } if !is_ident_name(name) { p.check(.name) diff --git a/vlib/v/slow_tests/inout/import_sym_field_no_warn.out b/vlib/v/slow_tests/inout/import_sym_field_no_warn.out new file mode 100644 index 000000000..09eb42eee --- /dev/null +++ b/vlib/v/slow_tests/inout/import_sym_field_no_warn.out @@ -0,0 +1 @@ +same_site_not_set diff --git a/vlib/v/slow_tests/inout/import_sym_field_no_warn.vv b/vlib/v/slow_tests/inout/import_sym_field_no_warn.vv new file mode 100644 index 000000000..9250634bb --- /dev/null +++ b/vlib/v/slow_tests/inout/import_sym_field_no_warn.vv @@ -0,0 +1,7 @@ +import net.http { SameSite } + +fn main() { + mime := SameSite.same_site_not_set + + println(mime) +} -- 2.39.5