diff --git a/vlib/strconv/ftoa/f64_str.v b/vlib/strconv/ftoa/f64_str.v index a93c0bf058..5655addf15 100644 --- a/vlib/strconv/ftoa/f64_str.v +++ b/vlib/strconv/ftoa/f64_str.v @@ -110,8 +110,8 @@ fn (d Dec64) get_string_64(neg bool, i_n_digit int, i_pad_digit int) string { out /= ten_pow_table_64[out_len - n_digit ] //println("out1:[$out] ${d.m / ten_pow_table_64[out_len - n_digit ]}") if d.m / ten_pow_table_64[out_len - n_digit ] < out { - d_exp += 1 - n_digit += 1 + d_exp++ + n_digit++ } //println("cmp: ${d.m/ten_pow_table_64[out_len - n_digit ]} ${out/ten_pow_table_64[out_len - n_digit ]}") diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 3a69f9bebf..9434dd9fd4 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -709,6 +709,9 @@ fn (mut c Checker) assign_expr(mut assign_expr ast.AssignExpr) { } else if !right.is_number() && right_type != table.string_type && !right.is_pointer() { c.error('operator += not defined on right operand type `$right.name`', assign_expr.val.position()) } + if assign_expr.val is ast.IntegerLiteral && assign_expr.val.str().int() == 1 { + c.error('use `++` instead of `+= 1`', assign_expr.pos) + } } .minus_assign { if !left.is_number() && !left.is_pointer() { @@ -716,6 +719,9 @@ fn (mut c Checker) assign_expr(mut assign_expr ast.AssignExpr) { } else if !right.is_number() && !right.is_pointer() { c.error('operator -= not defined on right operand type `$right.name`', assign_expr.val.position()) } + if assign_expr.val is ast.IntegerLiteral && assign_expr.val.str().int() == 1 { + c.error('use `--` instead of `-= 1`', assign_expr.pos) + } } .mult_assign, .div_assign { if !left.is_number() { diff --git a/vlib/v/checker/checker_test.v b/vlib/v/checker/checker_test.v index b590f5d32f..d6cabcd474 100644 --- a/vlib/v/checker/checker_test.v +++ b/vlib/v/checker/checker_test.v @@ -55,7 +55,7 @@ fn check_path(vexe, dir, voptions, result_extension string, tests []string) int println('found:') println(found) println('============\n') - nb_fail += 1 + nb_fail++ } else { println(term.green('OK')) os.rm(program) diff --git a/vlib/v/checker/tests/plus_or_minus_assign_one_err.out b/vlib/v/checker/tests/plus_or_minus_assign_one_err.out new file mode 100644 index 0000000000..7c9002cf11 --- /dev/null +++ b/vlib/v/checker/tests/plus_or_minus_assign_one_err.out @@ -0,0 +1,13 @@ +vlib/v/checker/tests/plus_or_minus_assign_one_err.v:3:6: error: use `++` instead of `+= 1` + 1 | fn main() { + 2 | mut foo := 10 + 3 | foo += 1 + | ~~ + 4 | foo -= 1 + 5 | } +vlib/v/checker/tests/plus_or_minus_assign_one_err.v:4:6: error: use `--` instead of `-= 1` + 2 | mut foo := 10 + 3 | foo += 1 + 4 | foo -= 1 + | ~~ + 5 | } diff --git a/vlib/v/checker/tests/plus_or_minus_assign_one_err.vv b/vlib/v/checker/tests/plus_or_minus_assign_one_err.vv new file mode 100644 index 0000000000..a0dead3ecf --- /dev/null +++ b/vlib/v/checker/tests/plus_or_minus_assign_one_err.vv @@ -0,0 +1,5 @@ +fn main() { + mut foo := 10 + foo += 1 + foo -= 1 +} \ No newline at end of file diff --git a/vlib/v/tests/option_test.v b/vlib/v/tests/option_test.v index c456b9ed60..5b0e834c4a 100644 --- a/vlib/v/tests/option_test.v +++ b/vlib/v/tests/option_test.v @@ -167,7 +167,7 @@ fn test_reassignment() { assert x2 == 777 x2 = 100 assert x2 == 100 - x2 += 1 + x2++ assert x2 == 101 // mut x3 := 0