From 7c58dfb88b2fabc5524d6787d4670fafb5a339a0 Mon Sep 17 00:00:00 2001 From: yuyi Date: Wed, 5 May 2021 19:11:32 +0800 Subject: [PATCH] checker: fix for_in mut var unused warning (#10008) --- vlib/v/checker/checker.v | 18 +++++++++--------- .../tests/no_warning_for_in_mut_var_unused.out | 0 .../tests/no_warning_for_in_mut_var_unused.vv | 7 +++++++ 3 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 vlib/v/checker/tests/no_warning_for_in_mut_var_unused.out create mode 100644 vlib/v/checker/tests/no_warning_for_in_mut_var_unused.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 10c98ee3da..602c7ece6c 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -3211,17 +3211,17 @@ pub fn (mut c Checker) assign_stmt(mut assign_stmt ast.AssignStmt) { left.info = ident_var_info if left_type != 0 { match mut left.obj { - ast.Var { left.obj.typ = left_type } - ast.GlobalField { left.obj.typ = left_type } + ast.Var { + left.obj.typ = left_type + if left.obj.is_auto_deref { + left.obj.is_used = true + } + } + ast.GlobalField { + left.obj.typ = left_type + } else {} } - /* - if left.obj is ast.Var as v { - v.typ = left_type - } else if left.obj is ast.GlobalDecl as v { - v.typ = left_type - } - */ } if is_decl { full_name := '${left.mod}.$left.name' diff --git a/vlib/v/checker/tests/no_warning_for_in_mut_var_unused.out b/vlib/v/checker/tests/no_warning_for_in_mut_var_unused.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/vlib/v/checker/tests/no_warning_for_in_mut_var_unused.vv b/vlib/v/checker/tests/no_warning_for_in_mut_var_unused.vv new file mode 100644 index 0000000000..3b66ce2a04 --- /dev/null +++ b/vlib/v/checker/tests/no_warning_for_in_mut_var_unused.vv @@ -0,0 +1,7 @@ +fn main() { + mut arr := [1, 2, 3] + for mut v in arr { + v = 2 + } + println(arr) +}