parser: disallow index variable with range `for` (#6464)

pull/6469/head
Nick Treleaven 2020-09-24 13:52:44 +01:00 committed by GitHub
parent fb45e2e046
commit 3925c3fa20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -113,6 +113,9 @@ fn (mut p Parser) for_stmt() ast.Stmt {
typ: table.int_type
pos: val_var_pos
})
if key_var_name.len > 0 {
p.error_with_pos('cannot declare index variable with range `for`', key_var_pos)
}
} else {
// this type will be set in checker
p.scope.register(val_var_name, ast.Var{

View File

@ -0,0 +1,4 @@
vlib/v/parser/tests/for.vv:1:5: error: cannot declare index variable with range `for`
1 | for i, k in 0..5 {
| ^
2 | }

View File

@ -0,0 +1,2 @@
for i, k in 0..5 {
}