parser: check var names in for loops

pull/4550/head
Kris Cherven 2020-04-21 21:48:51 -04:00 committed by GitHub
parent 155891a4e0
commit 5c3742fbd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 0 deletions

View File

@ -73,12 +73,23 @@ fn (var p Parser) for_stmt() ast.Stmt {
p.check(.comma)
key_var_name = val_var_name
val_var_name = p.check_name()
if p.scope.known_var(key_var_name) {
p.error('redefinition of `$key_var_name`')
}
if p.scope.known_var(val_var_name) {
p.error('redefinition of `$val_var_name`')
}
p.scope.register(key_var_name, ast.Var{
name: key_var_name
typ: table.int_type
})
} else if p.scope.known_var(val_var_name) {
p.error('redefinition of `$val_var_name`')
}
p.check(.key_in)
if p.tok.kind == .name && p.tok.lit in [key_var_name, val_var_name] {
p.error('redefinition of `$p.tok.lit`')
}
// arr_expr
cond := p.expr(0)
// 0 .. 10