From d97474d487c47a70a676381b718db25dffe0d1ef Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Wed, 6 Sep 2023 15:08:18 +0300 Subject: [PATCH] all: support -N, turning *all* notices into errors, to ease the process of finding places that may need attention/correction --- vlib/v/checker/checker.v | 3 +++ vlib/v/parser/parser.v | 4 ++++ vlib/v/pref/pref.v | 4 ++++ vlib/v/scanner/scanner.v | 31 +++++++++++++++---------------- 4 files changed, 26 insertions(+), 16 deletions(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index d0d7ec374d..e4c9f0fc6a 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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') diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 4ea12b1afc..204ea4ad8b 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -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 { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 28e90e3d37..6a1ecbd275 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -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 } diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 56de53987e..f88d0a0dd7 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -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