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

checker: fixed error pointer for "redefinition of key iteration variable" and "redefinition of value iteration variable" errors (#17121)

This commit is contained in:
Makhnev Petr 2023-01-26 14:31:35 +04:00 committed by GitHub
parent 21b17fe234
commit 15c0a73740
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 2 deletions

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/for_in_key_redefinition.vv:4:5: error: redefinition of key iteration variable `value`
2 | value := 2
3 |
4 | for value, _ in arr {
| ~~~~~
5 | println(value)
6 | }

View File

@ -0,0 +1,6 @@
arr := [1,2,3]
value := 2
for value, _ in arr {
println(value)
}

View File

@ -0,0 +1,7 @@
vlib/v/checker/tests/for_in_value_redefinition.vv:4:8: error: redefinition of value iteration variable `value`
2 | value := 2
3 |
4 | for _, value in arr {
| ~~~~~
5 | println(value)
6 | }

View File

@ -0,0 +1,6 @@
arr := [1,2,3]
value := 2
for _, value in arr {
println(value)
}

View File

@ -121,10 +121,12 @@ fn (mut p Parser) for_stmt() ast.Stmt {
val_var_pos) val_var_pos)
} }
if p.scope.known_var(key_var_name) { if p.scope.known_var(key_var_name) {
return p.error('redefinition of key iteration variable `${key_var_name}`') return p.error_with_pos('redefinition of key iteration variable `${key_var_name}`',
key_var_pos)
} }
if p.scope.known_var(val_var_name) { if p.scope.known_var(val_var_name) {
return p.error('redefinition of value iteration variable `${val_var_name}`') return p.error_with_pos('redefinition of value iteration variable `${val_var_name}`',
val_var_pos)
} }
p.scope.register(ast.Var{ p.scope.register(ast.Var{
name: key_var_name name: key_var_name