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

errors: use more distinct and detailed name redefinition messages

This commit is contained in:
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) name = p.prepend_mod(name)
} }
if _ := p.table.find_fn(name) { if _ := p.table.find_fn(name) {
p.error('redefinition of `$name`') p.error('redefinition of function `$name`')
} }
p.table.register_fn(table.Fn{ p.table.register_fn(table.Fn{
name: name name: name

View File

@ -74,21 +74,21 @@ fn (mut p Parser) for_stmt() ast.Stmt {
key_var_name = val_var_name key_var_name = val_var_name
val_var_name = p.check_name() val_var_name = p.check_name()
if p.scope.known_var(key_var_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) { 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{ p.scope.register(key_var_name, ast.Var{
name: key_var_name name: key_var_name
typ: table.int_type typ: table.int_type
}) })
} else if p.scope.known_var(val_var_name) { } 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) p.check(.key_in)
if p.tok.kind == .name && p.tok.lit in [key_var_name, val_var_name] { 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 // arr_expr
cond := p.expr(0) cond := p.expr(0)