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

v2: array_test fixes

This commit is contained in:
Alexander Medvednikov 2020-03-25 14:24:48 +01:00
parent aa0643f785
commit 456750ac19
4 changed files with 14 additions and 5 deletions

View File

@ -13,10 +13,10 @@ fn main() {
mut cmd := '$vexe -o v2 cmd/v' mut cmd := '$vexe -o v2 cmd/v'
if os.args.len >= 3 && os.args[2] == '-prod' { if os.args.len >= 3 && os.args[2] == '-prod' {
cmd = '$vexe -o v2 -prod cmd/v' cmd = '$vexe -o v2 -prod cmd/v'
println('V Self Compiling (-prod mode)...') println('V self compiling (-prod mode)...')
} }
else { else {
println('V Self Compiling...') println('V self compiling...')
} }
s2 := os.exec(cmd) or { panic(err) } s2 := os.exec(cmd) or { panic(err) }

View File

@ -288,7 +288,7 @@ fn test_fixed() {
assert nums[3] == 0 assert nums[3] == 0
nums[1] = 7 nums[1] = 7
assert nums[1] == 7 assert nums[1] == 7
nums2 := [N]int nums2 := [5]int // N
assert nums2[N - 1] == 0 assert nums2[N - 1] == 0
} }
@ -298,6 +298,7 @@ fn modify(numbers mut []int) {
fn test_mut_slice() { fn test_mut_slice() {
mut n := [1, 2, 3] mut n := [1, 2, 3]
//modify(mut n)
modify(mut n[..2]) modify(mut n[..2])
assert n[0] == 777 assert n[0] == 777
modify(mut n[2..]) modify(mut n[2..])
@ -574,7 +575,7 @@ fn test_push_many_self() {
fn test_for() { fn test_for() {
nums := [1,2,3] nums := [1,2,3]
mut sum := 0 mut sum := 0
for num <- nums { for num in nums {
sum += num sum += num
} }
assert sum == 6 assert sum == 6

View File

@ -531,6 +531,9 @@ fn (c mut Checker) stmt(node ast.Stmt) {
c.assign_stmt(mut it) c.assign_stmt(mut it)
c.expected_type = table.void_type c.expected_type = table.void_type
} }
ast.Block {
c.stmts(it.stmts)
}
// ast.Attr {} // ast.Attr {}
ast.CompIf { ast.CompIf {
// c.expr(it.cond) // c.expr(it.cond)

View File

@ -277,6 +277,11 @@ fn (g mut Gen) stmt(node ast.Stmt) {
ast.Attr { ast.Attr {
g.writeln('//[$it.name]') g.writeln('//[$it.name]')
} }
ast.Block {
g.writeln('{')
g.stmts(it.stmts)
g.writeln('}')
}
ast.BranchStmt { ast.BranchStmt {
// continue or break // continue or break
g.write(it.tok.kind.str()) g.write(it.tok.kind.str())
@ -952,7 +957,7 @@ fn (g mut Gen) expr(node ast.Expr) {
// TODO performance, detect `array` method differently // TODO performance, detect `array` method differently
['repeat', 'sort_with_compare', 'free', 'push_many', 'trim', ['repeat', 'sort_with_compare', 'free', 'push_many', 'trim',
// //
'first', 'last', 'clone'] { 'first', 'last', 'clone', 'reverse'] {
// && rec_sym.name == 'array' { // && rec_sym.name == 'array' {
// && rec_sym.name == 'array' && receiver_name.starts_with('array') { // && rec_sym.name == 'array' && receiver_name.starts_with('array') {
// `array_byte_clone` => `array_clone` // `array_byte_clone` => `array_clone`