diff --git a/cmd/tools/vcomplete.v b/cmd/tools/vcomplete.v index 8e61755a75..5754ce1ea6 100644 --- a/cmd/tools/vcomplete.v +++ b/cmd/tools/vcomplete.v @@ -131,6 +131,7 @@ const ( '-w', '-print-v-files', '-error-limit', + '-warn-error-limit', '-os', '-printfn', '-cflags', diff --git a/cmd/v/help/build.txt b/cmd/v/help/build.txt index a36ecec3e2..2916bca33b 100644 --- a/cmd/v/help/build.txt +++ b/cmd/v/help/build.txt @@ -82,6 +82,10 @@ NB: the build flags are shared with the run command too: d) the function name NB: if you want to output the profile info to stdout, use `-profile -`. + -warn-error-limit + Limit of warnings / errors that will be accumulated (defaults to 100). + Settings this to a negative value will disable the limit. + -profile-no-inline Skip [inline] functions when profiling. diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 020ddfd7f7..468c0d3546 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -7622,6 +7622,9 @@ fn (mut c Checker) warn_or_error(message string, pos token.Position, warn bool) } if warn && !c.pref.skip_warnings { c.nr_warnings++ + if c.nr_warnings >= c.pref.warn_error_limit && c.pref.warn_error_limit >= 0 { + return + } wrn := errors.Warning{ reporter: errors.Reporter.checker pos: pos @@ -7638,17 +7641,19 @@ fn (mut c Checker) warn_or_error(message string, pos token.Position, warn bool) exit(1) } c.nr_errors++ - if pos.line_nr !in c.error_lines { - err := errors.Error{ - reporter: errors.Reporter.checker - pos: pos - file_path: c.file.path - message: message - details: details + if c.nr_errors < c.pref.warn_error_limit || c.pref.warn_error_limit < 0 { + if pos.line_nr !in c.error_lines { + err := errors.Error{ + reporter: errors.Reporter.checker + pos: pos + file_path: c.file.path + message: message + details: details + } + c.file.errors << err + c.errors << err + c.error_lines << pos.line_nr } - c.file.errors << err - c.errors << err - c.error_lines << pos.line_nr } } } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index c0bba4f84d..e6248555b1 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1649,7 +1649,9 @@ pub fn (mut p Parser) error_with_error(error errors.Error) { eprintln(ferror) exit(1) } else { - p.errors << error + if p.errors.len < p.pref.warn_error_limit || p.pref.warn_error_limit < 0 { + p.errors << error + } } if p.pref.output_mode == .silent { // Normally, parser errors mean that the parser exits immediately, so there can be only 1 parser error. @@ -1672,11 +1674,13 @@ pub fn (mut p Parser) warn_with_pos(s string, pos token.Position) { ferror := util.formatted_error('warning:', s, p.file_name, pos) eprintln(ferror) } else { - p.warnings << errors.Warning{ - file_path: p.file_name - pos: pos - reporter: .parser - message: s + if p.warnings.len < p.pref.warn_error_limit || p.pref.warn_error_limit < 0 { + p.warnings << errors.Warning{ + file_path: p.file_name + pos: pos + reporter: .parser + message: s + } } } } diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 8ca843ac2a..37c79ff74f 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -189,6 +189,7 @@ pub mut: gc_mode GarbageCollectionMode = .no_gc // .no_gc, .boehm, .boehm_leak, ... is_cstrict bool // turn on more C warnings; slightly slower assert_failure_mode AssertFailureMode // whether to call abort() or print_backtrace() after an assertion failure + warn_error_limit int = 100 // limit of warnings/errors to be accumulated // checker settings: checker_match_exhaustive_cutoff_limit int = 12 } @@ -519,6 +520,10 @@ pub fn parse_args(known_external_commands []string, args []string) (&Preferences } i++ } + '-warn-error-limit' { + res.warn_error_limit = cmdline.option(current_args, arg, '10').int() + i++ + } '-cc' { res.ccompiler = cmdline.option(current_args, '-cc', 'cc') res.build_options << '$arg "$res.ccompiler"' diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 0e775244e9..3bcccedc1a 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -1354,11 +1354,13 @@ pub fn (mut s Scanner) warn(msg string) { if s.pref.output_mode == .stdout { eprintln(util.formatted_error('warning:', msg, s.file_path, pos)) } else { - s.warnings << errors.Warning{ - file_path: s.file_path - pos: pos - reporter: .scanner - message: msg + if s.warnings.len < s.pref.warn_error_limit || s.pref.warn_error_limit < 0 { + s.warnings << errors.Warning{ + file_path: s.file_path + pos: pos + reporter: .scanner + message: msg + } } } } @@ -1376,11 +1378,13 @@ pub fn (mut s Scanner) error(msg string) { if s.pref.fatal_errors { exit(1) } - s.errors << errors.Error{ - file_path: s.file_path - pos: pos - reporter: .scanner - message: msg + if s.errors.len < s.pref.warn_error_limit || s.pref.warn_error_limit < 0 { + s.errors << errors.Error{ + file_path: s.file_path + pos: pos + reporter: .scanner + message: msg + } } } }