fmt: fix ForInStmt

pull/4084/head
Alexey 2020-03-20 22:19:43 +03:00 committed by GitHub
parent 5a7f683f61
commit 9c668072b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 2 deletions

View File

@ -178,9 +178,15 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
f.writeln('}\n')
}
ast.ForInStmt {
f.write('for $it.key_var')
f.write('for ')
if it.key_var != '' {
f.write(it.key_var)
}
if it.val_var != '' {
f.write(', $it.val_var')
if it.key_var != '' {
f.write(', ')
}
f.write(it.val_var)
}
f.write(' in ')
f.expr(it.cond)

View File

@ -0,0 +1,17 @@
fn for_in_loop() {
for item in arr {
println(item)
}
}
fn for_in_loop_with_counter() {
for i, item in arr {
println(item)
}
}
fn for_in_loop_with_index_expr() {
for i in 0 .. 10 {
println(i)
}
}

View File

@ -0,0 +1,17 @@
fn for_in_loop() {
for item in arr {
println(item)
}
}
fn for_in_loop_with_counter() {
for i, item in arr {
println(item)
}
}
fn for_in_loop_with_index_expr() {
for i in 0..10 {
println(i)
}
}