From bf8ed1815ca8caf2ca5b6b723fe9be198b4ff9d1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 29 Apr 2020 12:38:36 +0300 Subject: [PATCH] builder: print collected checker warnings too --- vlib/v/builder/builder.v | 9 +++++++++ vlib/v/builder/c.v | 3 +++ vlib/v/checker/checker.v | 2 ++ 3 files changed, 14 insertions(+) diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 25b60813ba..35bcd6fe7a 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -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) } diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index cf9c43a1a5..77d3541e0f 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -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) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 5cb9c5e38c..abf226c5ad 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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