builder: print collected checker warnings too

pull/4644/head
Delyan Angelov 2020-04-29 12:38:36 +03:00
parent ad46e1b832
commit bf8ed1815c
3 changed files with 14 additions and 0 deletions

View File

@ -275,6 +275,15 @@ fn (b &Builder) print_errors(errors []errors.Error) {
}
}
fn (b &Builder) print_warnings(warnings []errors.Warning) {
for err in warnings {
kind := if b.pref.is_verbose { '$err.reporter warning #$b.checker.nr_errors:' } else { 'warning:' }
ferror := util.formatted_error(kind, err.message, err.file_path, err.pos)
eprintln(ferror)
}
}
fn verror(s string) {
util.verror('builder error', s)
}

View File

@ -18,6 +18,9 @@ pub fn (mut b Builder) gen_c(v_files []string) string {
t2 := time.ticks()
check_time := t2 - t1
b.info('CHECK: ${check_time}ms')
if b.checker.nr_warnings > 0 {
b.print_warnings(b.checker.warnings)
}
if b.checker.nr_errors > 0 {
b.print_errors(b.checker.errors)
exit(1)

View File

@ -21,6 +21,7 @@ pub struct Checker {
mut:
file ast.File
nr_errors int
nr_warnings int
errors []errors.Error
warnings []errors.Warning
error_lines []int // to avoid printing multiple errors for the same line
@ -1969,6 +1970,7 @@ fn (mut c Checker) warn_or_error(message string, pos token.Position, warn bool)
// print_backtrace()
// }
if warn {
c.nr_warnings++
c.warnings << errors.Warning{
reporter: errors.Reporter.checker
pos: pos