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

parser: check for loop key/val names

This commit is contained in:
Alexander Medvednikov 2020-06-24 16:54:21 +02:00
parent 4b0e606ae8
commit 8ac00b8711

View File

@ -73,6 +73,9 @@ fn (mut p Parser) for_stmt() ast.Stmt {
key_var_name = val_var_name
val_var_pos = p.tok.position()
val_var_name = p.check_name()
if key_var_name == val_var_name {
p.error_with_pos('key and value in a for loop cannot be the same', val_var_pos)
}
if p.scope.known_var(key_var_name) {
p.error('redefinition of key iteration variable `$key_var_name`')
}