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

parser: show location of a previously defined function

This commit is contained in:
Alexander Medvednikov 2020-05-20 17:27:31 +02:00
parent dd534fde57
commit 0d3f133436
4 changed files with 29 additions and 7 deletions

View File

@ -212,14 +212,12 @@ fn (b &Builder) print_warnings_and_errors() {
if b.checker.nr_errors > 0 {
exit(1)
}
return
}
if b.pref.is_verbose && b.checker.nr_warnings > 1 {
println('$b.checker.nr_warnings warnings')
}
if b.checker.nr_warnings > 0 && !b.pref.skip_warnings {
if b.checker.nr_warnings > 0 && !b.pref.skip_warnings {
for i, err in b.checker.warnings {
kind := if b.pref.is_verbose { '$err.reporter warning #$b.checker.nr_warnings:' } else { 'warning:' }
ferror := util.formatted_error(kind, err.message, err.file_path, err.pos)
@ -246,6 +244,24 @@ fn (b &Builder) print_warnings_and_errors() {
}
exit(1)
}
if b.table.redefined_fns.len > 0 {
for fn_name in b.table.redefined_fns {
eprintln('redefinition of function `$fn_name`')
// eprintln('previous declaration at')
// Find where this function was already declared
for file in b.parsed_files {
for stmt in file.stmts {
if stmt is ast.FnDecl {
f := stmt as ast.FnDecl
if f.name == fn_name {
println(file.path + ':' + f.pos.line_nr.str())
}
}
}
}
exit(1)
}
}
}
fn verror(s string) {

View File

@ -456,7 +456,8 @@ fn (mut p Parser) fn_redefinition_error(name string) {
}
*/
p.error('redefinition of function `$name`')
p.table.redefined_fns << name
// p.error('redefinition of function `$name`')
}
fn have_fn_main(stmts []ast.Stmt) bool {

View File

@ -664,12 +664,12 @@ fn (mut p Parser) parse_multi_expr() ast.Stmt {
} else if p.tok.kind.is_assign() {
epos := p.tok.position()
if collected.len == 1 {
return ast.ExprStmt {
return ast.ExprStmt{
expr: p.assign_expr(collected[0])
pos: epos
}
} else {
return ast.ExprStmt {
return ast.ExprStmt{
expr: p.assign_expr(ast.ConcatExpr{
vals: collected
})
@ -1044,7 +1044,11 @@ fn (mut p Parser) string_expr() ast.Expr {
node = ast.StringLiteral{
val: val
is_raw: is_raw
language: if is_cstr { table.Language.c } else { table.Language.v }
language: if is_cstr {
table.Language.c
} else {
table.Language.v
}
pos: pos
}
return node

View File

@ -14,6 +14,7 @@ pub mut:
imports []string // List of all imports
modules []string // List of all modules registered by the application
cflags []cflag.CFlag
redefined_fns []string
}
pub struct Fn {