all: support -N, turning *all* notices into errors, to ease the process of finding places that may need attention/correction

This commit is contained in:
Delyan Angelov 2023-09-06 15:08:18 +03:00
parent 37c189c75f
commit d97474d487
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
4 changed files with 26 additions and 16 deletions

View File

@ -4568,6 +4568,9 @@ fn (mut c Checker) note(message string, pos token.Pos) {
if c.is_generated {
return
}
if c.pref.notes_are_errors {
c.error(message, pos)
}
mut details := ''
if c.error_details.len > 0 {
details = c.error_details.join('\n')

View File

@ -2061,6 +2061,10 @@ fn (mut p Parser) note_with_pos(s string, pos token.Pos) {
if p.is_generated {
return
}
if p.pref.notes_are_errors {
p.error_with_pos(s, pos)
return
}
if p.pref.output_mode == .stdout && !p.pref.check_only {
util.show_compiler_message('notice:', pos: pos, file_path: p.file_name, message: s)
} else {

View File

@ -206,6 +206,7 @@ pub mut:
skip_warnings bool // like C's "-w", forces warnings to be ignored.
warn_impure_v bool // -Wimpure-v, force a warning for JS.fn()/C.fn(), outside of .js.v/.c.v files. TODO: turn to an error by default
warns_are_errors bool // -W, like C's "-Werror", treat *every* warning is an error
notes_are_errors bool // -N, treat *every* notice as an error
fatal_errors bool // unconditionally exit after the first error with exit(1)
reuse_tmpc bool // do not use random names for .tmp.c and .tmp.c.rsp files, and do not remove them
no_rsp bool // when true, pass C backend options directly on the CLI (do not use `.rsp` files for them, some older C compilers do not support them)
@ -665,6 +666,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
'-W' {
res.warns_are_errors = true
}
'-N' {
res.notes_are_errors = true
}
'-no-rsp' {
res.no_rsp = true
}

View File

@ -1578,7 +1578,19 @@ fn (mut s Scanner) inc_line_number() {
}
}
pub fn (mut s Scanner) current_pos() token.Pos {
return token.Pos{
line_nr: s.line_nr
pos: s.pos
col: s.current_column() - 1
}
}
pub fn (mut s Scanner) note(msg string) {
if s.pref.notes_are_errors {
s.error_with_pos(msg, s.current_pos())
return
}
pos := token.Pos{
line_nr: s.line_nr
pos: s.pos
@ -1614,12 +1626,7 @@ fn (mut s Scanner) eat_details() string {
}
pub fn (mut s Scanner) warn(msg string) {
pos := token.Pos{
line_nr: s.line_nr
pos: s.pos
col: s.current_column() - 1
}
s.warn_with_pos(msg, pos)
s.warn_with_pos(msg, s.current_pos())
}
pub fn (mut s Scanner) warn_with_pos(msg string, pos token.Pos) {
@ -1651,12 +1658,7 @@ pub fn (mut s Scanner) warn_with_pos(msg string, pos token.Pos) {
}
pub fn (mut s Scanner) error(msg string) {
pos := token.Pos{
line_nr: s.line_nr
pos: s.pos
col: s.current_column() - 1
}
s.error_with_pos(msg, pos)
s.error_with_pos(msg, s.current_pos())
}
pub fn (mut s Scanner) error_with_pos(msg string, pos token.Pos) {
@ -1697,10 +1699,7 @@ fn (mut s Scanner) vet_error(msg string, fix vet.FixKind) {
ve := vet.Error{
message: msg
file_path: s.file_path
pos: token.Pos{
line_nr: s.line_nr
col: s.current_column() - 1
}
pos: s.current_pos()
kind: .error
fix: fix
typ: .default