all: add limit to accumulated errors / warnings (#11183)

pull/11184/head
Leo Developer 2021-08-14 18:49:21 +02:00 committed by GitHub
parent deb26b92b9
commit 8a8a0932f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 26 deletions

View File

@ -131,6 +131,7 @@ const (
'-w',
'-print-v-files',
'-error-limit',
'-warn-error-limit',
'-os',
'-printfn',
'-cflags',

View File

@ -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>
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.

View File

@ -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
}
}
}

View File

@ -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
}
}
}
}

View File

@ -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"'

View File

@ -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
}
}
}
}