Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement --warningAsError:on and enforce it for compiler sources; fix some bugs with warningAsError:foo:on|off #14068

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
## Compiler changes

- Specific warnings can now be turned into errors via `--warningAsError[X]:on|off`.
- `--warningAsError:on|off` turns all enabled warnings into errors (or back to warnings),
- `--warningAsError:on` is now enabled in compiler/config.nims
- The `define` and `undef` pragmas have been de-deprecated.

## Tool changes
Expand Down
20 changes: 13 additions & 7 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,18 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
localError(conf, info, errOnOrOffExpectedButXFound % arg)
elif n notin conf.cmdlineNotes or pass == passCmd1:
if pass == passCmd1: incl(conf.cmdlineNotes, n)
incl(conf.modifiedyNotes, n)
case val
of "on":
if state == wWarningAsError:
if state == wWarningAsError: # this also enables the warning
incl(conf.warningAsErrors, n)
else:
incl(conf.notes, n)
incl(conf.mainPackageNotes, n)
incl(conf.modifiedyNotes, n)
incl(conf.notes, n)
incl(conf.mainPackageNotes, n)
of "off":
if state == wWarningAsError:
if state == wWarningAsError: # this does not disable the warning
excl(conf.warningAsErrors, n)
else:
incl(conf.modifiedyNotes, n) # incl intended
excl(conf.notes, n)
excl(conf.mainPackageNotes, n)
excl(conf.foreignPackageNotes, n)
Expand Down Expand Up @@ -534,7 +534,13 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
if processOnOffSwitchOrList(conf, {optWarns}, arg, pass, info): listWarnings(conf)
of "warning": processSpecificNote(arg, wWarning, pass, info, switch, conf)
of "hint": processSpecificNote(arg, wHint, pass, info, switch, conf)
of "warningaserror": processSpecificNote(arg, wWarningAsError, pass, info, switch, conf)
of "warningaserror":
case arg.normalize
of "", "on":
for a in warnMin..warnMax: incl(conf.warningAsErrors, a)
of "off":
for a in warnMin..warnMax: excl(conf.warningAsErrors, a)
else: processSpecificNote(arg, wWarningAsError, pass, info, switch, conf)
of "hints":
if processOnOffSwitchOrList(conf, {optHints}, arg, pass, info): listHints(conf)
of "threadanalysis": processOnOffSwitchG(conf, {optThreadAnalysis}, arg, pass, info)
Expand Down
1 change: 1 addition & 0 deletions compiler/condsyms.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,4 @@ proc initDefines*(symbols: StringTableRef) =
defineSymbol("nimNewIntegerOps")
defineSymbol("nimHasInvariant")
defineSymbol("nimHasStacktraceMsgs")
defineSymbol("nimHasWarningAsErrorAll")
4 changes: 4 additions & 0 deletions compiler/config.nims
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
when defined nimHasWarningAsErrorAll:
# keep this flag on to prevent future warning regressions, but if unbearable,
# disable specific ones via `switch("warningAsError", "foo:off")`
switch("warningAsError", "on")
2 changes: 1 addition & 1 deletion compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string)
if conf.cmd == cmdIdeTools: log(s)
quit(conf, msg)
if msg >= errMin and msg <= errMax or
(msg in warnMin..warnMax and msg in conf.warningAsErrors):
(conf.hasWarn(msg) and msg in conf.warningAsErrors):
inc(conf.errorCounter)
conf.exitcode = 1'i8
if conf.errorCounter >= conf.errorMax:
Expand Down
2 changes: 1 addition & 1 deletion compiler/semparallel.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# - output slices need special logic (+)

import
ast, astalgo, idents, lowerings, magicsys, guards, sempass2, msgs,
ast, astalgo, idents, lowerings, magicsys, guards, msgs,
renderer, types, modulegraphs, options, spawn, lineinfos

from trees import getMagic, isTrue, getRoot
Expand Down
1 change: 1 addition & 0 deletions doc/advopt.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Advanced options:
--hint[X]:on|off turn specific hint X on|off
--warningAsError[X]:on|off
turn specific warning X into an error on|off
--warningAsError:on|off turn all enabled warnings on|off (since 1.3.2)
--styleCheck:off|hint|error
produce hints or errors for Nim identifiers that
do not adhere to Nim's official style guide
Expand Down
2 changes: 1 addition & 1 deletion lib/system.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ const
NimMinor* {.intdefine.}: int = 3
## is the minor number of Nim's version.

NimPatch* {.intdefine.}: int = 1
NimPatch* {.intdefine.}: int = 2
## is the patch number of Nim's version.

NimVersion*: string = $NimMajor & "." & $NimMinor & "." & $NimPatch
Expand Down