errors: use more distinct and detailed name redefinition messages

pull/4561/head
Delyan Angelov 2020-04-23 13:14:54 +03:00
parent bea918bb87
commit 8b5573a6f3
2 changed files with 5 additions and 5 deletions

View File

@ -191,7 +191,7 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
name = p.prepend_mod(name)
}
if _ := p.table.find_fn(name) {
p.error('redefinition of `$name`')
p.error('redefinition of function `$name`')
}
p.table.register_fn(table.Fn{
name: name

View File

@ -74,21 +74,21 @@ fn (mut p Parser) for_stmt() ast.Stmt {
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`')
p.error('redefinition of key iteration variable `$key_var_name`')
}
if p.scope.known_var(val_var_name) {
p.error('redefinition of `$val_var_name`')
p.error('redefinition of value iteration variable `$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.error('redefinition of value iteration variable `$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`')
p.error('in a `for x in array` loop, the key or value iteration variable `$p.tok.lit` can not be the same as the array variable')
}
// arr_expr
cond := p.expr(0)