mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: use ++ / -- instead of += 1 / -= 1
This commit is contained in:
parent
a3a91f54a9
commit
90279a7108
@ -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 ]}")
|
||||
|
@ -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() {
|
||||
|
@ -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)
|
||||
|
13
vlib/v/checker/tests/plus_or_minus_assign_one_err.out
Normal file
13
vlib/v/checker/tests/plus_or_minus_assign_one_err.out
Normal file
@ -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 | }
|
5
vlib/v/checker/tests/plus_or_minus_assign_one_err.vv
Normal file
5
vlib/v/checker/tests/plus_or_minus_assign_one_err.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
mut foo := 10
|
||||
foo += 1
|
||||
foo -= 1
|
||||
}
|
@ -167,7 +167,7 @@ fn test_reassignment() {
|
||||
assert x2 == 777
|
||||
x2 = 100
|
||||
assert x2 == 100
|
||||
x2 += 1
|
||||
x2++
|
||||
assert x2 == 101
|
||||
//
|
||||
mut x3 := 0
|
||||
|
Loading…
Reference in New Issue
Block a user