From c7a6d28e13e6a72ed1fe4b78d1f5c26f7d99990e Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 23 Apr 2021 13:33:48 +0300 Subject: [PATCH] all: improve unused variable warning (fix `x = 1`, `x += 1` etc) --- thirdparty/sokol/sokol_app2.h | 8 ++-- vlib/builtin/builtin.c.v | 22 +++++----- vlib/builtin/builtin_nix.c.v | 1 + vlib/os/os_c.v | 3 +- vlib/os/process_nix.c.v | 7 ++-- vlib/v/cflag/cflags.v | 4 +- vlib/v/checker/checker.v | 11 +++-- .../checker/tests/array_or_map_assign_err.out | 18 ++++----- .../checker/tests/array_or_map_assign_err.vv | 5 +++ .../tests/arrow_op_wrong_left_type_err_b.out | 3 +- .../tests/arrow_op_wrong_left_type_err_b.vv | 1 + .../checker/tests/assign_expr_type_err_a.out | 3 +- .../v/checker/tests/assign_expr_type_err_a.vv | 3 +- .../checker/tests/assign_expr_type_err_b.out | 3 +- .../v/checker/tests/assign_expr_type_err_b.vv | 3 +- .../checker/tests/assign_expr_type_err_c.out | 3 +- .../v/checker/tests/assign_expr_type_err_c.vv | 3 +- .../checker/tests/assign_expr_type_err_d.out | 3 +- .../v/checker/tests/assign_expr_type_err_d.vv | 3 +- .../checker/tests/assign_expr_type_err_e.out | 3 +- .../v/checker/tests/assign_expr_type_err_e.vv | 3 +- .../checker/tests/assign_expr_type_err_f.out | 3 +- .../v/checker/tests/assign_expr_type_err_f.vv | 3 +- .../checker/tests/assign_expr_type_err_g.out | 3 +- .../v/checker/tests/assign_expr_type_err_g.vv | 3 +- .../checker/tests/assign_expr_type_err_h.out | 3 +- .../v/checker/tests/assign_expr_type_err_h.vv | 3 +- .../checker/tests/assign_expr_type_err_i.out | 5 ++- .../v/checker/tests/assign_expr_type_err_i.vv | 5 ++- ...gn_expr_unresolved_variables_err_chain.out | 6 +-- ...ign_expr_unresolved_variables_err_chain.vv | 3 ++ vlib/v/checker/tests/assign_sumtype_err.out | 3 +- vlib/v/checker/tests/assign_sumtype_err.vv | 3 +- vlib/v/checker/tests/enum_as_int_err.out | 5 ++- vlib/v/checker/tests/enum_as_int_err.vv | 1 + vlib/v/checker/tests/error_with_unicode.out | 7 ++-- vlib/v/checker/tests/error_with_unicode.vv | 1 + vlib/v/checker/tests/fixed_array_conv.out | 40 +++++++++---------- vlib/v/checker/tests/fixed_array_conv.vv | 2 + vlib/v/checker/tests/fn_var.out | 12 +++--- vlib/v/checker/tests/fn_var.vv | 1 + vlib/v/checker/tests/immutable_var.out | 3 +- vlib/v/checker/tests/immutable_var.vv | 1 + vlib/v/checker/tests/map_init_wrong_type.out | 5 ++- vlib/v/checker/tests/map_init_wrong_type.vv | 1 + vlib/v/checker/tests/method_op_err.out | 35 ++++++++-------- vlib/v/checker/tests/method_op_err.vv | 3 +- vlib/v/checker/tests/ptr_assign.out | 1 + vlib/v/checker/tests/ptr_assign.vv | 1 + .../struct_assigned_to_pointer_to_struct.out | 5 ++- .../struct_assigned_to_pointer_to_struct.vv | 1 + vlib/v/checker/tests/sum.out | 5 ++- vlib/v/checker/tests/sum.vv | 1 + .../tests/sum_type_assign_non_variant_err.out | 3 +- .../tests/sum_type_assign_non_variant_err.vv | 1 + .../tests/var_used_before_declaration.out | 4 +- .../tests/var_used_before_declaration.vv | 3 +- vlib/v/checker/tests/void_fn_as_value.vv | 1 + vlib/v/gen/c/fn.v | 2 +- vlib/v/parser/parser.v | 9 ++++- vlib/v/parser/tests/prefix_first.out | 26 ++++++------ vlib/v/parser/tests/prefix_first.vv | 1 + vlib/v/parser/tests/unnecessary_mut.vv | 1 + vlib/v/pref/default.v | 2 +- 64 files changed, 199 insertions(+), 141 deletions(-) diff --git a/thirdparty/sokol/sokol_app2.h b/thirdparty/sokol/sokol_app2.h index 7cddcdbb9..aa6d65451 100644 --- a/thirdparty/sokol/sokol_app2.h +++ b/thirdparty/sokol/sokol_app2.h @@ -1,14 +1,14 @@ @implementation MyView2 -int xx = 0; +int __v_sokol_inited = 0; // Alternative drawRect which calls a frame function with native Cocoa calls - (void)drawRect:(NSRect)rect { - puts("drawRect()"); - if (xx == 0) { + //puts("drawRect()"); + if (__v_sokol_inited == 0) { _sapp_call_init(); - xx = 1; + __v_sokol_inited = 1; } _sapp_call_frame_native(); } diff --git a/vlib/builtin/builtin.c.v b/vlib/builtin/builtin.c.v index 4167a7d3c..45dc9dba6 100644 --- a/vlib/builtin/builtin.c.v +++ b/vlib/builtin/builtin.c.v @@ -120,12 +120,11 @@ pub fn eprintln(s string) { C.fprintf(C.stderr, c'%.*s\n', s.len, s.str) } } $else { - mut n := 0 if s.str == 0 { - n = C.write(2, c'eprintln(NIL)\n', 14) + _ = C.write(2, c'eprintln(NIL)\n', 14) } else { - n = C.write(2, s.str, s.len) - n = C.write(2, c'\n', 1) + _ = C.write(2, s.str, s.len) + _ = C.write(2, c'\n', 1) } } C.fflush(C.stderr) @@ -158,11 +157,10 @@ pub fn eprint(s string) { C.fprintf(C.stderr, c'%.*s', s.len, s.str) } } $else { - mut n := 0 if s.str == 0 { - n = C.write(2, c'eprint(NIL)', 11) + _ = C.write(2, c'eprint(NIL)', 11) } else { - n = C.write(2, s.str, s.len) + _ = C.write(2, s.str, s.len) } } C.fflush(C.stderr) @@ -172,7 +170,6 @@ pub fn eprint(s string) { // print prints a message to stdout. Unlike `println` stdout is not automatically flushed. // A call to `flush()` will flush the output buffer to stdout. pub fn print(s string) { - mut n := 0 $if android { C.fprintf(C.stdout, c'%.*s', s.len, s.str) } $else $if ios { @@ -181,7 +178,7 @@ pub fn print(s string) { } $else $if freestanding { bare_print(s.str, u64(s.len)) } $else { - n = C.write(1, s.str, s.len) + _ = C.write(1, s.str, s.len) } } @@ -194,7 +191,6 @@ fn C.asl_log(voidptr, voidptr, int, charptr) */ // println prints a message with a line end, to stdout. stdout is flushed. pub fn println(s string) { - mut n := 0 if s.str == 0 { $if android { C.fprintf(C.stdout, c'println(NIL)\n') @@ -204,7 +200,7 @@ pub fn println(s string) { bare_print(s.str, u64(s.len)) bare_print(c'println(NIL)\n', 13) } $else { - n = C.write(1, c'println(NIL)\n', 13) + _ = C.write(1, c'println(NIL)\n', 13) } return } @@ -216,8 +212,8 @@ pub fn println(s string) { bare_print(s.str, u64(s.len)) bare_print(c'\n', 1) } $else { - n = C.write(1, s.str, s.len) - n = C.write(1, c'\n', 1) + _ = C.write(1, s.str, s.len) + _ = C.write(1, c'\n', 1) } } diff --git a/vlib/builtin/builtin_nix.c.v b/vlib/builtin/builtin_nix.c.v index 7b5860d42..ba44219ac 100644 --- a/vlib/builtin/builtin_nix.c.v +++ b/vlib/builtin/builtin_nix.c.v @@ -145,5 +145,6 @@ fn break_if_debugger_attached() { unsafe { mut ptr := &voidptr(0) *ptr = voidptr(0) + _ = ptr } } diff --git a/vlib/os/os_c.v b/vlib/os/os_c.v index f29ef2bb3..55cd5a02c 100644 --- a/vlib/os/os_c.v +++ b/vlib/os/os_c.v @@ -740,11 +740,10 @@ pub fn is_link(path string) bool { // chdir changes the current working directory to the new directory in `path`. pub fn chdir(path string) { - mut n := 0 $if windows { C._wchdir(path.to_wide()) } $else { - n = C.chdir(&char(path.str)) + _ = C.chdir(&char(path.str)) } } diff --git a/vlib/os/process_nix.c.v b/vlib/os/process_nix.c.v index 38b55a99c..74140d124 100644 --- a/vlib/os/process_nix.c.v +++ b/vlib/os/process_nix.c.v @@ -3,12 +3,11 @@ module os fn C.setpgid(pid int, pgid int) int fn (mut p Process) unix_spawn_process() int { - mut n := 0 mut pipeset := [6]int{} if p.use_stdio_ctl { - n = C.pipe(&pipeset[0]) // pipe read end 0 <- 1 pipe write end - n = C.pipe(&pipeset[2]) // pipe read end 2 <- 3 pipe write end - n = C.pipe(&pipeset[4]) // pipe read end 4 <- 5 pipe write end + _ = C.pipe(&pipeset[0]) // pipe read end 0 <- 1 pipe write end + _ = C.pipe(&pipeset[2]) // pipe read end 2 <- 3 pipe write end + _ = C.pipe(&pipeset[4]) // pipe read end 4 <- 5 pipe write end } pid := fork() if pid != 0 { diff --git a/vlib/v/cflag/cflags.v b/vlib/v/cflag/cflags.v index 6e17becdc..30da3b6b1 100644 --- a/vlib/v/cflag/cflags.v +++ b/vlib/v/cflag/cflags.v @@ -33,10 +33,10 @@ pub fn (cf &CFlag) eval() string { sparams := remainder[cflag.fexisting_literal.len + 1..].all_before(')') i += sparams.len + cflag.fexisting_literal.len + 1 svalues := sparams.replace(',', '\n').split_into_lines().map(it.trim(' \'"')) - mut found_spath := '' + // mut found_spath := '' for spath in svalues { if os.exists(spath) { - found_spath = spath + // found_spath = spath value += spath continue cflag_eval_outer_loop } diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index db0d9742d..a2c6fcc63 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -119,7 +119,7 @@ pub fn (mut c Checker) check_scope_vars(sc &ast.Scope) { match obj { ast.Var { if !c.pref.is_repl { - if !obj.is_used && obj.name[0] != `_` { + if !obj.is_used && obj.name[0] != `_` && !c.file.is_test { c.warn('unused variable: `$obj.name`', obj.pos) } } @@ -2570,7 +2570,10 @@ pub fn (mut c Checker) selector_expr(mut selector_expr ast.SelectorExpr) ast.Typ // c.using_new_err_struct = using_new_err_struct_save if typ == ast.void_type_idx { - c.error('unknown selector expression', selector_expr.pos) + // This means that the variable's value was assigned to an + // unknown function or method, so the error was already handled + // earlier + // c.error('unknown selector expression', selector_expr.pos) return ast.void_type } selector_expr.expr_type = typ @@ -3644,7 +3647,7 @@ fn (mut c Checker) stmt(node ast.Stmt) { fn (mut c Checker) assert_stmt(node ast.AssertStmt) { cur_exp_typ := c.expected_type assert_type := c.check_expr_opt_call(node.expr, c.expr(node.expr)) - if assert_type != ast.bool_type_idx { + if assert_type != ast.bool_type_idx && assert_type != ast.void_type_idx { atype_name := c.table.get_type_symbol(assert_type).name c.error('assert can be used only with `bool` expressions, but found `$atype_name` instead', node.pos) @@ -4763,7 +4766,7 @@ pub fn (mut c Checker) ident(mut ident ast.Ident) ast.Type { } ast.Var { // incase var was not marked as used yet (vweb tmpl) - obj.is_used = true + // obj.is_used = true if ident.pos.pos < obj.pos.pos { c.error('undefined variable `$ident.name` (used before declaration)', ident.pos) diff --git a/vlib/v/checker/tests/array_or_map_assign_err.out b/vlib/v/checker/tests/array_or_map_assign_err.out index dbbeb3b18..c1788de34 100644 --- a/vlib/v/checker/tests/array_or_map_assign_err.out +++ b/vlib/v/checker/tests/array_or_map_assign_err.out @@ -10,10 +10,10 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:5:5: error: use `array2 = array1 4 | mut a3 := []int{} 5 | a3 = a1 | ^ - 6 | + 6 | 7 | m1 := {'one': 1} vlib/v/checker/tests/array_or_map_assign_err.vv:8:8: error: cannot copy map: call `move` or `clone` method (or use a reference) - 6 | + 6 | 7 | m1 := {'one': 1} 8 | m2 := m1 | ~~ @@ -24,12 +24,12 @@ vlib/v/checker/tests/array_or_map_assign_err.vv:10:7: error: cannot copy map: ca 9 | mut m3 := map[string]int{} 10 | m3 = m1 | ~~ - 11 | + 11 | 12 | _ = a2 -vlib/v/checker/tests/array_or_map_assign_err.vv:20:8: error: cannot copy map: call `move` or `clone` method (or use a reference) - 18 | - 19 | fn foo(mut m map[string]int) { - 20 | m2 := m +vlib/v/checker/tests/array_or_map_assign_err.vv:25:8: error: cannot copy map: call `move` or `clone` method (or use a reference) + 23 | + 24 | fn foo(mut m map[string]int) { + 25 | m2 := m | ^ - 21 | m['foo'] = 100 - 22 | println(m) + 26 | m['foo'] = 100 + 27 | println(m) diff --git a/vlib/v/checker/tests/array_or_map_assign_err.vv b/vlib/v/checker/tests/array_or_map_assign_err.vv index a86494db2..f2463c800 100644 --- a/vlib/v/checker/tests/array_or_map_assign_err.vv +++ b/vlib/v/checker/tests/array_or_map_assign_err.vv @@ -14,6 +14,11 @@ fn main() { mut m := {'foo':1} foo(mut m) + + _ = a3 + _ = m1 + _ = m2 + _ = m3 } fn foo(mut m map[string]int) { diff --git a/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.out b/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.out index a85a42176..61d6c9948 100644 --- a/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.out +++ b/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.vv:4:8: error: cannot assign 3 | mut obj := 9 4 | obj = <-ch | ~~ - 5 | } + 5 | _ = obj + 6 | } diff --git a/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.vv b/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.vv index 22661ed70..3e842d93f 100644 --- a/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.vv +++ b/vlib/v/checker/tests/arrow_op_wrong_left_type_err_b.vv @@ -2,4 +2,5 @@ fn main() { ch := chan string{} mut obj := 9 obj = <-ch + _ = obj } diff --git a/vlib/v/checker/tests/assign_expr_type_err_a.out b/vlib/v/checker/tests/assign_expr_type_err_a.out index 38397cbcf..cba2860bf 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_a.out +++ b/vlib/v/checker/tests/assign_expr_type_err_a.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_a.vv:3:2: error: operator <<= not defi 2 | mut foo := 0.5 3 | foo <<= 1 | ~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_a.vv b/vlib/v/checker/tests/assign_expr_type_err_a.vv index 7daa532fb..8ea403d1e 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_a.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_a.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 0.5 foo <<= 1 -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_b.out b/vlib/v/checker/tests/assign_expr_type_err_b.out index a9ff8ddf7..e5f01cafc 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_b.out +++ b/vlib/v/checker/tests/assign_expr_type_err_b.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_b.vv:3:9: error: operator %= not defin 2 | mut foo := 10 3 | foo %= 'hello' | ~~~~~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_b.vv b/vlib/v/checker/tests/assign_expr_type_err_b.vv index 1841f55b1..db28266d7 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_b.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_b.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 10 foo %= 'hello' -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_c.out b/vlib/v/checker/tests/assign_expr_type_err_c.out index f688fab8e..338ce5b87 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_c.out +++ b/vlib/v/checker/tests/assign_expr_type_err_c.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_c.vv:3:2: error: operator *= not defin 2 | mut foo := 'hello' 3 | foo *= 10 | ~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_c.vv b/vlib/v/checker/tests/assign_expr_type_err_c.vv index e0cec9694..98409ac25 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_c.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_c.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 'hello' foo *= 10 -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_d.out b/vlib/v/checker/tests/assign_expr_type_err_d.out index b408b6393..77536290e 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_d.out +++ b/vlib/v/checker/tests/assign_expr_type_err_d.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_d.vv:3:9: error: operator /= not defin 2 | mut foo := 1.5 3 | foo /= true | ~~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_d.vv b/vlib/v/checker/tests/assign_expr_type_err_d.vv index 58857d39c..ca5c0ee8e 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_d.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_d.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 1.5 foo /= true -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_e.out b/vlib/v/checker/tests/assign_expr_type_err_e.out index 713316f76..b8acd99bc 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_e.out +++ b/vlib/v/checker/tests/assign_expr_type_err_e.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_e.vv:3:2: error: operator `-=` not def 2 | mut foo := 'hello' 3 | foo -= `a` | ~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_e.vv b/vlib/v/checker/tests/assign_expr_type_err_e.vv index c3c7e230e..b6a4473d3 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_e.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_e.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 'hello' foo -= `a` -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_f.out b/vlib/v/checker/tests/assign_expr_type_err_f.out index 180a10006..7cdaa51a4 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_f.out +++ b/vlib/v/checker/tests/assign_expr_type_err_f.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_f.vv:3:9: error: invalid right operand 2 | mut foo := 10 3 | foo -= false | ~~~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_f.vv b/vlib/v/checker/tests/assign_expr_type_err_f.vv index a6b378bdd..70213c44c 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_f.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_f.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 10 foo -= false -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_g.out b/vlib/v/checker/tests/assign_expr_type_err_g.out index 75d620506..e017d7b53 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_g.out +++ b/vlib/v/checker/tests/assign_expr_type_err_g.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_g.vv:3:2: error: operator `+=` not def 2 | mut foo := true 3 | foo += false | ~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_g.vv b/vlib/v/checker/tests/assign_expr_type_err_g.vv index 621c5ce40..c9380f479 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_g.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_g.vv @@ -1,4 +1,5 @@ fn main() { mut foo := true foo += false -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_h.out b/vlib/v/checker/tests/assign_expr_type_err_h.out index 873f33b5f..07d2b6e9d 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_h.out +++ b/vlib/v/checker/tests/assign_expr_type_err_h.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_expr_type_err_h.vv:3:9: error: invalid right operand 2 | mut foo := 'hello' 3 | foo += false | ~~~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_h.vv b/vlib/v/checker/tests/assign_expr_type_err_h.vv index ea1c7c4ec..51b2207d4 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_h.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_h.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 'hello' foo += false -} \ No newline at end of file + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_type_err_i.out b/vlib/v/checker/tests/assign_expr_type_err_i.out index 3d1413046..c8450f0fd 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_i.out +++ b/vlib/v/checker/tests/assign_expr_type_err_i.out @@ -1,6 +1,7 @@ vlib/v/checker/tests/assign_expr_type_err_i.vv:3:9: error: invalid right operand: f64 += string 1 | fn main() { 2 | mut foo := 1.5 - 3 | foo += 'hello' + 3 | foo += 'hello' | ~~~~~~~ - 4 | } + 4 | _ = foo + 5 | } diff --git a/vlib/v/checker/tests/assign_expr_type_err_i.vv b/vlib/v/checker/tests/assign_expr_type_err_i.vv index 8b58aea97..2debbae1b 100644 --- a/vlib/v/checker/tests/assign_expr_type_err_i.vv +++ b/vlib/v/checker/tests/assign_expr_type_err_i.vv @@ -1,4 +1,5 @@ fn main() { mut foo := 1.5 - foo += 'hello' -} \ No newline at end of file + foo += 'hello' + _ = foo +} diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.out b/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.out index da2e847e7..5c7e5cf95 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.out +++ b/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.out @@ -1,13 +1,13 @@ -vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv:2:7: error: undefined variable `b` (used before declaration) +vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv:2:7: error: undefined variable `b` (used before declaration) 1 | fn main() { 2 | a := b | ^ 3 | b := c 4 | c := a -vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv:3:7: error: undefined variable `c` (used before declaration) +vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv:3:7: error: undefined variable `c` (used before declaration) 1 | fn main() { 2 | a := b 3 | b := c | ^ 4 | c := a - 5 | } + 5 | _ = a diff --git a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv b/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv index 1f8308c67..279d6f5f8 100644 --- a/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv +++ b/vlib/v/checker/tests/assign_expr_unresolved_variables_err_chain.vv @@ -2,4 +2,7 @@ fn main() { a := b b := c c := a + _ = a + _ = b + _ = c } diff --git a/vlib/v/checker/tests/assign_sumtype_err.out b/vlib/v/checker/tests/assign_sumtype_err.out index 4df3d61b1..ebb4b7aab 100644 --- a/vlib/v/checker/tests/assign_sumtype_err.out +++ b/vlib/v/checker/tests/assign_sumtype_err.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/assign_sumtype_err.vv:13:9: error: cannot assign to `decl`: 12 | mut decl := Decl{} 13 | decl = stmt | ~~~~ - 14 | } + 14 | _ = decl + 15 | } diff --git a/vlib/v/checker/tests/assign_sumtype_err.vv b/vlib/v/checker/tests/assign_sumtype_err.vv index 1225f833d..94e6fa1d1 100644 --- a/vlib/v/checker/tests/assign_sumtype_err.vv +++ b/vlib/v/checker/tests/assign_sumtype_err.vv @@ -11,4 +11,5 @@ fn main() { stmt := Stmt(Decl{}) mut decl := Decl{} decl = stmt -} \ No newline at end of file + _ = decl +} diff --git a/vlib/v/checker/tests/enum_as_int_err.out b/vlib/v/checker/tests/enum_as_int_err.out index be6c8fa26..cef283d0c 100644 --- a/vlib/v/checker/tests/enum_as_int_err.out +++ b/vlib/v/checker/tests/enum_as_int_err.out @@ -11,10 +11,11 @@ vlib/v/checker/tests/enum_as_int_err.vv:10:8: error: cannot assign to `foo`: exp 10 | foo = Color.red | ~~~~~~~~~ 11 | println(color == 0) - 12 | } + 12 | _ = foo vlib/v/checker/tests/enum_as_int_err.vv:11:10: error: infix expr: cannot use `int literal` (right expression) as `Color` 9 | color = 1 10 | foo = Color.red 11 | println(color == 0) | ~~~~~~~~~~ - 12 | } \ No newline at end of file + 12 | _ = foo + 13 | } diff --git a/vlib/v/checker/tests/enum_as_int_err.vv b/vlib/v/checker/tests/enum_as_int_err.vv index ac3d501fe..47605ae01 100644 --- a/vlib/v/checker/tests/enum_as_int_err.vv +++ b/vlib/v/checker/tests/enum_as_int_err.vv @@ -9,4 +9,5 @@ fn main() { color = 1 foo = Color.red println(color == 0) + _ = foo } diff --git a/vlib/v/checker/tests/error_with_unicode.out b/vlib/v/checker/tests/error_with_unicode.out index a521ceff6..78ea8323e 100644 --- a/vlib/v/checker/tests/error_with_unicode.out +++ b/vlib/v/checker/tests/error_with_unicode.out @@ -1,5 +1,5 @@ vlib/v/checker/tests/error_with_unicode.vv:5:17: error: cannot use `int literal` as `string` in argument 2 to `f1` - 3 | + 3 | 4 | fn main() { 5 | f1('🐀🐈', 0) | ^ @@ -46,10 +46,11 @@ vlib/v/checker/tests/error_with_unicode.vv:12:6: error: cannot assign to `n`: ex 12 | n = '한글' | ~~~~~~ 13 | n = 'Кириллица' - 14 | } + 14 | _ = n vlib/v/checker/tests/error_with_unicode.vv:13:6: error: cannot assign to `n`: expected `int`, not `string` 11 | n = '繁體字' 12 | n = '한글' 13 | n = 'Кириллица' | ~~~~~~~~~~~ - 14 | } + 14 | _ = n + 15 | } diff --git a/vlib/v/checker/tests/error_with_unicode.vv b/vlib/v/checker/tests/error_with_unicode.vv index af3edc446..8299e4e43 100644 --- a/vlib/v/checker/tests/error_with_unicode.vv +++ b/vlib/v/checker/tests/error_with_unicode.vv @@ -11,4 +11,5 @@ fn main() { n = '繁體字' n = '한글' n = 'Кириллица' + _ = n } diff --git a/vlib/v/checker/tests/fixed_array_conv.out b/vlib/v/checker/tests/fixed_array_conv.out index 3e3c405f2..7cc36f1b2 100644 --- a/vlib/v/checker/tests/fixed_array_conv.out +++ b/vlib/v/checker/tests/fixed_array_conv.out @@ -11,31 +11,31 @@ vlib/v/checker/tests/fixed_array_conv.vv:5:4: error: mismatched types `&int` and 5 | ip = arr | ^ 6 | _ = &int(arr) - 7 | + 7 | _ = p vlib/v/checker/tests/fixed_array_conv.vv:6:6: error: cannot cast a fixed array (use e.g. `&arr[0]` instead) 4 | mut ip := &int(0) 5 | ip = arr 6 | _ = &int(arr) | ~~~~~~~~ - 7 | - 8 | unsafe { -vlib/v/checker/tests/fixed_array_conv.vv:9:13: error: cannot use `[2]int` as `voidptr` in argument 1 to `memdup` - 7 | - 8 | unsafe { - 9 | _ = memdup(arr, 1) + 7 | _ = p + 8 | _ = ip +vlib/v/checker/tests/fixed_array_conv.vv:11:13: error: cannot use `[2]int` as `voidptr` in argument 1 to `memdup` + 9 | + 10 | unsafe { + 11 | _ = memdup(arr, 1) | ~~~ - 10 | _ = tos(arr, 1) - 11 | fn (p &int){}(arr) -vlib/v/checker/tests/fixed_array_conv.vv:10:10: error: cannot use `[2]int` as `&byte` in argument 1 to `tos` - 8 | unsafe { - 9 | _ = memdup(arr, 1) - 10 | _ = tos(arr, 1) + 12 | _ = tos(arr, 1) + 13 | fn (p &int){}(arr) +vlib/v/checker/tests/fixed_array_conv.vv:12:10: error: cannot use `[2]int` as `&byte` in argument 1 to `tos` + 10 | unsafe { + 11 | _ = memdup(arr, 1) + 12 | _ = tos(arr, 1) | ~~~ - 11 | fn (p &int){}(arr) - 12 | } -vlib/v/checker/tests/fixed_array_conv.vv:11:16: error: cannot use `[2]int` as `&int` in argument 1 to `anon` - 9 | _ = memdup(arr, 1) - 10 | _ = tos(arr, 1) - 11 | fn (p &int){}(arr) + 13 | fn (p &int){}(arr) + 14 | } +vlib/v/checker/tests/fixed_array_conv.vv:13:16: error: cannot use `[2]int` as `&int` in argument 1 to `anon` + 11 | _ = memdup(arr, 1) + 12 | _ = tos(arr, 1) + 13 | fn (p &int){}(arr) | ~~~ - 12 | } + 14 | } diff --git a/vlib/v/checker/tests/fixed_array_conv.vv b/vlib/v/checker/tests/fixed_array_conv.vv index e789d87c1..8c343c4f8 100644 --- a/vlib/v/checker/tests/fixed_array_conv.vv +++ b/vlib/v/checker/tests/fixed_array_conv.vv @@ -4,6 +4,8 @@ p = arr mut ip := &int(0) ip = arr _ = &int(arr) +_ = p +_ = ip unsafe { _ = memdup(arr, 1) diff --git a/vlib/v/checker/tests/fn_var.out b/vlib/v/checker/tests/fn_var.out index d1db2a0f0..d3487a110 100644 --- a/vlib/v/checker/tests/fn_var.out +++ b/vlib/v/checker/tests/fn_var.out @@ -14,10 +14,10 @@ vlib/v/checker/tests/fn_var.vv:4:5: error: cannot assign to `p`: expected `&fn ( 3 | mut p := &f 4 | p = &[f] | ^ - 5 | i := 0 - 6 | println(i) -vlib/v/checker/tests/fn_var.vv:7:31: error: undefined ident: `i` - 5 | i := 0 - 6 | println(i) - 7 | f = fn(mut a []int) { println(i) } + 5 | _ = p + 6 | i := 0 +vlib/v/checker/tests/fn_var.vv:8:31: error: undefined ident: `i` + 6 | i := 0 + 7 | println(i) + 8 | f = fn(mut a []int) { println(i) } | ^ diff --git a/vlib/v/checker/tests/fn_var.vv b/vlib/v/checker/tests/fn_var.vv index c94a87267..0a48b5d74 100644 --- a/vlib/v/checker/tests/fn_var.vv +++ b/vlib/v/checker/tests/fn_var.vv @@ -2,6 +2,7 @@ mut f := fn(i int) byte {} f = 4 mut p := &f p = &[f] +_ = p i := 0 println(i) f = fn(mut a []int) { println(i) } diff --git a/vlib/v/checker/tests/immutable_var.out b/vlib/v/checker/tests/immutable_var.out index c62c94f83..012ef94dc 100644 --- a/vlib/v/checker/tests/immutable_var.out +++ b/vlib/v/checker/tests/immutable_var.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/immutable_var.vv:3:2: error: `a` is immutable, declare it w 2 | a := 1 3 | a = 2 | ^ - 4 | } + 4 | _ = a + 5 | } diff --git a/vlib/v/checker/tests/immutable_var.vv b/vlib/v/checker/tests/immutable_var.vv index d83612c7b..aeeaef1b4 100644 --- a/vlib/v/checker/tests/immutable_var.vv +++ b/vlib/v/checker/tests/immutable_var.vv @@ -1,4 +1,5 @@ fn main() { a := 1 a = 2 + _ = a } diff --git a/vlib/v/checker/tests/map_init_wrong_type.out b/vlib/v/checker/tests/map_init_wrong_type.out index e83cc1ce0..283edf7bb 100644 --- a/vlib/v/checker/tests/map_init_wrong_type.out +++ b/vlib/v/checker/tests/map_init_wrong_type.out @@ -11,10 +11,11 @@ vlib/v/checker/tests/map_init_wrong_type.vv:4:17: error: invalid map key: expect 4 | _ = {2:0 3:0 "hi":0} | ~~~~ 5 | _ = {2:0 3:`@` 4:0} - 6 | } + 6 | _ = a vlib/v/checker/tests/map_init_wrong_type.vv:5:15: error: invalid map value: expected `int`, not `rune` 3 | a = { 'x': 12.3 } 4 | _ = {2:0 3:0 "hi":0} 5 | _ = {2:0 3:`@` 4:0} | ~~~ - 6 | } + 6 | _ = a + 7 | } diff --git a/vlib/v/checker/tests/map_init_wrong_type.vv b/vlib/v/checker/tests/map_init_wrong_type.vv index fb77120b1..56b7b960f 100644 --- a/vlib/v/checker/tests/map_init_wrong_type.vv +++ b/vlib/v/checker/tests/map_init_wrong_type.vv @@ -3,4 +3,5 @@ fn main() { a = { 'x': 12.3 } _ = {2:0 3:0 "hi":0} _ = {2:0 3:`@` 4:0} + _ = a } diff --git a/vlib/v/checker/tests/method_op_err.out b/vlib/v/checker/tests/method_op_err.out index 07ced3bcb..547ceea90 100644 --- a/vlib/v/checker/tests/method_op_err.out +++ b/vlib/v/checker/tests/method_op_err.out @@ -46,25 +46,24 @@ vlib/v/checker/tests/method_op_err.vv:34:13: error: mismatched types `User` and 34 | println(User{3, 4} < Foo{3, 4}) | ~~~~~~~~~~~~~~~~~~~~~~ 35 | mut u := User{3, 4} - 36 | u += 12 -vlib/v/checker/tests/method_op_err.vv:36:10: error: cannot assign to `u`: expected `User`, not `int literal` - 34 | println(User{3, 4} < Foo{3, 4}) + 36 | _ = u +vlib/v/checker/tests/method_op_err.vv:37:10: error: cannot assign to `u`: expected `User`, not `int literal` 35 | mut u := User{3, 4} - 36 | u += 12 + 36 | _ = u + 37 | u += 12 | ~~ - 37 | u %= User{1, 3} - 38 | u += User{2, 3} -vlib/v/checker/tests/method_op_err.vv:37:5: error: operator %= not defined on left operand type `User` - 35 | mut u := User{3, 4} - 36 | u += 12 - 37 | u %= User{1, 3} + 38 | u %= User{1, 3} + 39 | u += User{2, 3} +vlib/v/checker/tests/method_op_err.vv:38:5: error: operator %= not defined on left operand type `User` + 36 | _ = u + 37 | u += 12 + 38 | u %= User{1, 3} | ^ - 38 | u += User{2, 3} - 39 | } -vlib/v/checker/tests/method_op_err.vv:38:7: error: operator `+` must return `User` to be used as an assignment operator - 36 | u += 12 - 37 | u %= User{1, 3} - 38 | u += User{2, 3} + 39 | u += User{2, 3} + 40 | } +vlib/v/checker/tests/method_op_err.vv:39:7: error: operator `+` must return `User` to be used as an assignment operator + 37 | u += 12 + 38 | u %= User{1, 3} + 39 | u += User{2, 3} | ~~ - 39 | } - + 40 | } diff --git a/vlib/v/checker/tests/method_op_err.vv b/vlib/v/checker/tests/method_op_err.vv index 94239b90f..24a82dd20 100644 --- a/vlib/v/checker/tests/method_op_err.vv +++ b/vlib/v/checker/tests/method_op_err.vv @@ -33,7 +33,8 @@ fn main() { println(User{3, 2} < User{2, 4}) println(User{3, 4} < Foo{3, 4}) mut u := User{3, 4} + _ = u u += 12 u %= User{1, 3} - u += User{2, 3} + u += User{2, 3} } diff --git a/vlib/v/checker/tests/ptr_assign.out b/vlib/v/checker/tests/ptr_assign.out index f4de352c2..5afa1d243 100644 --- a/vlib/v/checker/tests/ptr_assign.out +++ b/vlib/v/checker/tests/ptr_assign.out @@ -3,3 +3,4 @@ vlib/v/checker/tests/ptr_assign.vv:3:5: error: cannot assign to `p`: expected `& 2 | mut p := &v 3 | p = 4 | ^ + 4 | _ = p diff --git a/vlib/v/checker/tests/ptr_assign.vv b/vlib/v/checker/tests/ptr_assign.vv index 1b8cbe456..562f1968e 100644 --- a/vlib/v/checker/tests/ptr_assign.vv +++ b/vlib/v/checker/tests/ptr_assign.vv @@ -1,3 +1,4 @@ mut v := 43 mut p := &v p = 4 +_ = p diff --git a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out index 734ec37fc..666f29561 100644 --- a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out +++ b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.out @@ -4,10 +4,11 @@ vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:5:4: error: mismatc 5 | f = { x: 223344 } | ^ 6 | f = Foo{ x: 20 } - 7 | } + 7 | _ = f vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv:6:4: error: mismatched types `&Foo` and `Foo` 4 | mut f := &Foo{ 10 } 5 | f = { x: 223344 } 6 | f = Foo{ x: 20 } | ^ - 7 | } + 7 | _ = f + 8 | } diff --git a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv index ec9573cc4..f281856e9 100644 --- a/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv +++ b/vlib/v/checker/tests/struct_assigned_to_pointer_to_struct.vv @@ -4,4 +4,5 @@ fn main() { mut f := &Foo{ 10 } f = { x: 223344 } f = Foo{ x: 20 } + _ = f } diff --git a/vlib/v/checker/tests/sum.out b/vlib/v/checker/tests/sum.out index 8f57bcfb4..5c92692ca 100644 --- a/vlib/v/checker/tests/sum.out +++ b/vlib/v/checker/tests/sum.out @@ -13,7 +13,7 @@ vlib/v/checker/tests/sum.vv:6:8: error: cannot cast non-sum type `int` using `as 7 | } 8 | vlib/v/checker/tests/sum.vv:10:7: error: cannot cast `rune` to `Var` - 8 | + 8 | 9 | fn sum() { 10 | _ := Var(`J`) | ~~~~~~~~ @@ -24,4 +24,5 @@ vlib/v/checker/tests/sum.vv:12:7: error: cannot assign to `s2`: expected `Var`, 11 | mut s2 := Var('') 12 | s2 = true | ~~~~ - 13 | } \ No newline at end of file + 13 | _ = s2 + 14 | } diff --git a/vlib/v/checker/tests/sum.vv b/vlib/v/checker/tests/sum.vv index 1693732fa..6796a2e58 100644 --- a/vlib/v/checker/tests/sum.vv +++ b/vlib/v/checker/tests/sum.vv @@ -10,4 +10,5 @@ fn sum() { _ := Var(`J`) mut s2 := Var('') s2 = true + _ = s2 } diff --git a/vlib/v/checker/tests/sum_type_assign_non_variant_err.out b/vlib/v/checker/tests/sum_type_assign_non_variant_err.out index 62893b3e1..1a9ea9971 100644 --- a/vlib/v/checker/tests/sum_type_assign_non_variant_err.out +++ b/vlib/v/checker/tests/sum_type_assign_non_variant_err.out @@ -3,4 +3,5 @@ vlib/v/checker/tests/sum_type_assign_non_variant_err.vv:11:6: error: cannot assi 10 | mut w := Stmt(AnotherThing{}) 11 | w = IfExpr{} | ~~~~~~~~ - 12 | } + 12 | _ = w + 13 | } diff --git a/vlib/v/checker/tests/sum_type_assign_non_variant_err.vv b/vlib/v/checker/tests/sum_type_assign_non_variant_err.vv index 68f36ec1b..1ab9a2cf0 100644 --- a/vlib/v/checker/tests/sum_type_assign_non_variant_err.vv +++ b/vlib/v/checker/tests/sum_type_assign_non_variant_err.vv @@ -9,4 +9,5 @@ struct AnotherThing {} fn main() { mut w := Stmt(AnotherThing{}) w = IfExpr{} + _ = w } diff --git a/vlib/v/checker/tests/var_used_before_declaration.out b/vlib/v/checker/tests/var_used_before_declaration.out index 3909edde4..b3ea3617f 100644 --- a/vlib/v/checker/tests/var_used_before_declaration.out +++ b/vlib/v/checker/tests/var_used_before_declaration.out @@ -1,6 +1,6 @@ -vlib/v/checker/tests/var_used_before_declaration.vv:2:13: error: undefined variable `x` (used before declaration) +vlib/v/checker/tests/var_used_before_declaration.vv:2:13: error: undefined variable `x` (used before declaration) 1 | fn main() { 2 | println(x) | ^ 3 | x := 'hello v' - 4 | } + 4 | _ = x diff --git a/vlib/v/checker/tests/var_used_before_declaration.vv b/vlib/v/checker/tests/var_used_before_declaration.vv index 5f2d8e393..1a2b63d39 100644 --- a/vlib/v/checker/tests/var_used_before_declaration.vv +++ b/vlib/v/checker/tests/var_used_before_declaration.vv @@ -1,4 +1,5 @@ fn main() { println(x) x := 'hello v' -} \ No newline at end of file + _ = x +} diff --git a/vlib/v/checker/tests/void_fn_as_value.vv b/vlib/v/checker/tests/void_fn_as_value.vv index 1ab139432..012019e7c 100644 --- a/vlib/v/checker/tests/void_fn_as_value.vv +++ b/vlib/v/checker/tests/void_fn_as_value.vv @@ -5,4 +5,5 @@ fn main() { a += x('a','b') mut b := 'abcdef' _ = b + _ = a } diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 6c6c909d2..2479eb36d 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -1033,7 +1033,7 @@ fn (mut g Gen) autofree_call_postgen(node_pos int) { // this means this tmp expr var has already been freed continue } - obj.is_used = true + obj.is_used = true // TODO bug? sets all vars is_used to true g.autofree_variable(obj) // g.nr_vars_to_free-- } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 130febd6a..e52644c80 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1947,7 +1947,14 @@ pub fn (mut p Parser) name_expr() ast.Expr { opt := if p.tok.lit == 'r' { '`r` (raw string)' } else { '`c` (c string)' } return p.error('cannot use $opt with `byte` and `rune`') } - known_var := p.mark_var_as_used(p.tok.lit) + // Make sure that the var is not marked as used in assignments: `x = 1`, `x += 2` etc + // but only when it's actually used (e.g. `println(x)`) + known_var := if p.peek_tok.kind.is_assign() { + p.scope.known_var(p.tok.lit) + } else { + p.mark_var_as_used(p.tok.lit) + } + // Handle modules mut is_mod_cast := false if p.peek_tok.kind == .dot && !known_var && (language != .v || p.known_import(p.tok.lit) || p.mod.all_after_last('.') == p.tok.lit) { diff --git a/vlib/v/parser/tests/prefix_first.out b/vlib/v/parser/tests/prefix_first.out index e91f5a4d8..3a4adc679 100644 --- a/vlib/v/parser/tests/prefix_first.out +++ b/vlib/v/parser/tests/prefix_first.out @@ -4,14 +4,14 @@ vlib/v/parser/tests/prefix_first.vv:15:3: warning: move infix `-` operator befor 15 | -1 | ^ 16 | } else {1} - 17 | } -vlib/v/parser/tests/prefix_first.vv:26:3: warning: move infix `&` operator before new line (if infix intended) or use brackets for a prefix expression - 24 | _ = opt() or { - 25 | _ = 1 - 26 | &v + 17 | _ = p +vlib/v/parser/tests/prefix_first.vv:27:3: warning: move infix `&` operator before new line (if infix intended) or use brackets for a prefix expression + 25 | _ = opt() or { + 26 | _ = 1 + 27 | &v | ^ - 27 | } - 28 | } + 28 | } + 29 | } vlib/v/parser/tests/prefix_first.vv:13:6: error: `if` expression requires an expression as the last statement of every branch 11 | 12 | // later this should compile correctly @@ -19,10 +19,10 @@ vlib/v/parser/tests/prefix_first.vv:13:6: error: `if` expression requires an exp | ~~~~~~~ 14 | v = 1 15 | -1 -vlib/v/parser/tests/prefix_first.vv:24:12: error: last statement in the `or {}` block should be an expression of type `&int` or exit parent scope - 22 | // later this should compile correctly - 23 | v := 3 - 24 | _ = opt() or { +vlib/v/parser/tests/prefix_first.vv:25:12: error: last statement in the `or {}` block should be an expression of type `&int` or exit parent scope + 23 | // later this should compile correctly + 24 | v := 3 + 25 | _ = opt() or { | ~~~~ - 25 | _ = 1 - 26 | &v + 26 | _ = 1 + 27 | &v diff --git a/vlib/v/parser/tests/prefix_first.vv b/vlib/v/parser/tests/prefix_first.vv index 3e9c5a5bf..83e180c29 100644 --- a/vlib/v/parser/tests/prefix_first.vv +++ b/vlib/v/parser/tests/prefix_first.vv @@ -14,6 +14,7 @@ fn test_prefix() { v = 1 -1 } else {1} + _ = p } fn opt() ?&int {return none} diff --git a/vlib/v/parser/tests/unnecessary_mut.vv b/vlib/v/parser/tests/unnecessary_mut.vv index e52a2d9ac..6c7a470ed 100644 --- a/vlib/v/parser/tests/unnecessary_mut.vv +++ b/vlib/v/parser/tests/unnecessary_mut.vv @@ -3,4 +3,5 @@ fn main() { if mut x == 0 { println(true) } + _ = x } diff --git a/vlib/v/pref/default.v b/vlib/v/pref/default.v index 0d0b8ad9c..aff3acce0 100644 --- a/vlib/v/pref/default.v +++ b/vlib/v/pref/default.v @@ -93,7 +93,7 @@ pub fn (mut p Preferences) fill_with_defaults() { } p.find_cc_if_cross_compiling() p.ccompiler_type = cc_from_string(p.ccompiler) - p.is_test = p.path.ends_with('_test.v') || p.path.ends_with('_test.vv') + p.is_test = p.path.ends_with('_test.v') || p.path.ends_with('.vv') || p.path.ends_with('.vv') || p.path.all_before_last('.v').all_before_last('.').ends_with('_test') p.is_vsh = p.path.ends_with('.vsh') p.is_script = p.is_vsh || p.path.ends_with('.v') || p.path.ends_with('.vv') -- 2.30.2