parser: show location of a previously defined function
parent
dd534fde57
commit
0d3f133436
|
@ -212,10 +212,8 @@ 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')
|
||||
}
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue