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

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

This commit is contained in:
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 {
}