v.builder: improve builder error messages (fix #14386) (#14421)

master
yuyi 2022-05-17 17:12:20 +08:00 committed by GitHub
parent 60e817ff32
commit d7b1e57186
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 15 deletions

View File

@ -556,7 +556,9 @@ pub fn (mut b Builder) print_warnings_and_errors() {
}
}
if redefines.len > 0 {
eprintln('redefinition of function `$fn_name`')
ferror := util.formatted_error('builder error:', 'redefinition of function `$fn_name`',
'', token.Pos{})
eprintln(ferror)
for redefine in redefines {
eprintln(util.formatted_error('conflicting declaration:', redefine.fheader,
redefine.fpath, redefine.f.pos))

View File

@ -1,13 +1,12 @@
redefinition of function `main.f`
builder error: redefinition of function `f`
vlib/v/checker/tests/fn_duplicate.vv:1:1: conflicting declaration: fn f()
1 | fn f() {
| ~~~~~~
2 |
3 | }
vlib/v/checker/tests/fn_duplicate.vv:5:1: conflicting declaration: fn f(i int)
3 | }
4 |
5 | fn f(i int) {
2 | }
3 |
vlib/v/checker/tests/fn_duplicate.vv:4:1: conflicting declaration: fn f(i int)
2 | }
3 |
4 | fn f(i int) {
| ~~~~~~~~~~~
6 |
7 | }
5 | }

View File

@ -1,7 +1,5 @@
fn f() {
}
fn f(i int) {
}

View File

@ -86,14 +86,18 @@ pub fn formatted_error(kind string, omsg string, filepath string, pos token.Pos)
path = path.replace_once(util.normalised_workdir, '')
}
}
//
position := '$path:${pos.line_nr + 1}:${mu.max(1, pos.col + 1)}:'
position := if filepath.len > 0 {
'$path:${pos.line_nr + 1}:${mu.max(1, pos.col + 1)}:'
} else {
''
}
scontext := source_file_context(kind, filepath, pos).join('\n')
final_position := bold(position)
final_kind := bold(color(kind, kind))
final_msg := emsg
final_context := if scontext.len > 0 { '\n$scontext' } else { '' }
//
return '$final_position $final_kind $final_msg$final_context'.trim_space()
}