1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

use ++ everywhere

This commit is contained in:
Alexander Medvednikov 2019-12-08 14:34:51 +03:00
parent cc682eafe1
commit c9886e6f42
8 changed files with 17 additions and 16 deletions

View File

@ -203,7 +203,7 @@ fn (p mut Parser) match_statement(is_expr bool) string {
i++ i++
p.fgen_nl() p.fgen_nl()
} }
p.error('match expression requires `else`') p.error('match must be exhaustive')
//p.returns = false // only get here when no default, so return is not guaranteed //p.returns = false // only get here when no default, so return is not guaranteed
return '' return ''
} }

View File

@ -1386,8 +1386,8 @@ fn ($v.name mut $v.typ) $p.cur_fn.name (...) {
} }
else { else {
next := p.peek_token() next := p.peek_token()
if next.tok == .number && next.lit== '1' { if next.tok == .number && next.lit== '1' {
p.warn('use ++ instead of += 1') p.error('use `++` instead of `+= 1`')
} }
p.gen(' += ') p.gen(' += ')
} }

View File

@ -16,7 +16,7 @@ fn test_defer() {
} }
fn set_num(i int, n mut Num) { fn set_num(i int, n mut Num) {
defer { n.val+=1 } defer { n.val++ }
println("Hi") println("Hi")
if i < 5 { if i < 5 {
return return

View File

@ -41,7 +41,8 @@ fn test_mut_2() {
b.a[zero].v << 5 b.a[zero].v << 5
b.a[0].v[zero] = 3 b.a[0].v[zero] = 3
b.a[0].v[b.a[zero].v[zero]] += 1b.a[0].v[b.a[0].v[zero]] += 1 b.a[0].v[b.a[zero].v[zero]]++
b.a[0].v[b.a[0].v[zero]]++
assert b.a[0].v.len == 5 assert b.a[0].v.len == 5
assert b.a[0].v[0] == 3 assert b.a[0].v[0] == 3

View File

@ -3,7 +3,7 @@ fn test_pointer_arithmetic() {
arr := [1,2,3,4] arr := [1,2,3,4]
unsafe { unsafe {
mut parr := *int(arr.data) mut parr := *int(arr.data)
parr += 1 parr++
assert 2 == *parr assert 2 == *parr
parr++ parr++
assert 3 == *parr assert 3 == *parr

View File

@ -339,7 +339,7 @@ fn main() {
mut total_frames := u32(0) mut total_frames := u32(0)
for { for {
total_frames += 1 total_frames++
start_ticks := sdl.get_perf_counter() start_ticks := sdl.get_perf_counter()
g1 := game g1 := game

View File

@ -19,7 +19,7 @@ pub fn new_builder(initial_size int) Builder {
pub fn (b mut Builder) write_b(data byte) { pub fn (b mut Builder) write_b(data byte) {
b.buf << data b.buf << data
b.len += 1 b.len++
} }
pub fn (b mut Builder) write(s string) { pub fn (b mut Builder) write(s string) {

View File

@ -44,7 +44,7 @@ fn test_byte_write() {
mut count := 0 mut count := 0
for word in temp_str { for word in temp_str {
sb.write_b(word) sb.write_b(word)
count += 1 count++
assert count == sb.len assert count == sb.len
} }
assert sb.str() == temp_str assert sb.str() == temp_str