--hintAsError (#16763)
* --hintAsError * add test, changelog * condsyms
This commit is contained in:
parent
2bedb0fe2c
commit
4fc7fcb775
8 changed files with 56 additions and 9 deletions
|
|
@ -135,6 +135,7 @@ with other backends. see #9125. Use `-d:nimLegacyJsRound` for previous behavior.
|
||||||
- Type mismatch errors now show more context, use `-d:nimLegacyTypeMismatch` for previous
|
- Type mismatch errors now show more context, use `-d:nimLegacyTypeMismatch` for previous
|
||||||
behavior.
|
behavior.
|
||||||
|
|
||||||
|
- Added `--hintAsError` with similar semantics as `--warningAsError`.
|
||||||
|
|
||||||
## Tool changes
|
## Tool changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,8 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
|
||||||
if i == arg.len: discard
|
if i == arg.len: discard
|
||||||
elif i < arg.len and (arg[i] in {':', '='}): inc(i)
|
elif i < arg.len and (arg[i] in {':', '='}): inc(i)
|
||||||
else: invalidCmdLineOption(conf, pass, orig, info)
|
else: invalidCmdLineOption(conf, pass, orig, info)
|
||||||
if state == wHint:
|
# unfortunately, hintUser and warningUser clash
|
||||||
|
if state in {wHint, wHintAsError}:
|
||||||
let x = findStr(hintMin, hintMax, id, errUnknown)
|
let x = findStr(hintMin, hintMax, id, errUnknown)
|
||||||
if x != errUnknown: n = TNoteKind(x)
|
if x != errUnknown: n = TNoteKind(x)
|
||||||
else: localError(conf, info, "unknown hint: " & id)
|
else: localError(conf, info, "unknown hint: " & id)
|
||||||
|
|
@ -209,13 +210,13 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
|
||||||
incl(conf.modifiedyNotes, n)
|
incl(conf.modifiedyNotes, n)
|
||||||
case val
|
case val
|
||||||
of "on":
|
of "on":
|
||||||
if state == wWarningAsError:
|
if state in {wWarningAsError, wHintAsError}:
|
||||||
incl(conf.warningAsErrors, n)
|
incl(conf.warningAsErrors, n) # xxx rename warningAsErrors to noteAsErrors
|
||||||
else:
|
else:
|
||||||
incl(conf.notes, n)
|
incl(conf.notes, n)
|
||||||
incl(conf.mainPackageNotes, n)
|
incl(conf.mainPackageNotes, n)
|
||||||
of "off":
|
of "off":
|
||||||
if state == wWarningAsError:
|
if state in {wWarningAsError, wHintAsError}:
|
||||||
excl(conf.warningAsErrors, n)
|
excl(conf.warningAsErrors, n)
|
||||||
else:
|
else:
|
||||||
excl(conf.notes, n)
|
excl(conf.notes, n)
|
||||||
|
|
@ -607,6 +608,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
of "warning": processSpecificNote(arg, wWarning, pass, info, switch, conf)
|
of "warning": processSpecificNote(arg, wWarning, pass, info, switch, conf)
|
||||||
of "hint": processSpecificNote(arg, wHint, pass, info, switch, conf)
|
of "hint": processSpecificNote(arg, wHint, pass, info, switch, conf)
|
||||||
of "warningaserror": processSpecificNote(arg, wWarningAsError, pass, info, switch, conf)
|
of "warningaserror": processSpecificNote(arg, wWarningAsError, pass, info, switch, conf)
|
||||||
|
of "hintaserror": processSpecificNote(arg, wHintAsError, pass, info, switch, conf)
|
||||||
of "hints":
|
of "hints":
|
||||||
if processOnOffSwitchOrList(conf, {optHints}, arg, pass, info): listHints(conf)
|
if processOnOffSwitchOrList(conf, {optHints}, arg, pass, info): listHints(conf)
|
||||||
of "threadanalysis": processOnOffSwitchG(conf, {optThreadAnalysis}, arg, pass, info)
|
of "threadanalysis": processOnOffSwitchG(conf, {optThreadAnalysis}, arg, pass, info)
|
||||||
|
|
|
||||||
|
|
@ -124,3 +124,4 @@ proc initDefines*(symbols: StringTableRef) =
|
||||||
defineSymbol("nimHasCastPragmaBlocks")
|
defineSymbol("nimHasCastPragmaBlocks")
|
||||||
defineSymbol("nimHasDeclaredLocs")
|
defineSymbol("nimHasDeclaredLocs")
|
||||||
defineSymbol("nimHasJsBigIntBackend")
|
defineSymbol("nimHasJsBigIntBackend")
|
||||||
|
defineSymbol("nimHasHintAsError")
|
||||||
|
|
|
||||||
|
|
@ -413,7 +413,7 @@ proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string)
|
||||||
if conf.cmd == cmdIdeTools: log(s)
|
if conf.cmd == cmdIdeTools: log(s)
|
||||||
quit(conf, msg)
|
quit(conf, msg)
|
||||||
if msg >= errMin and msg <= errMax or
|
if msg >= errMin and msg <= errMax or
|
||||||
(msg in warnMin..warnMax and msg in conf.warningAsErrors):
|
(msg in warnMin..hintMax and msg in conf.warningAsErrors):
|
||||||
inc(conf.errorCounter)
|
inc(conf.errorCounter)
|
||||||
conf.exitcode = 1'i8
|
conf.exitcode = 1'i8
|
||||||
if conf.errorCounter >= conf.errorMax:
|
if conf.errorCounter >= conf.errorMax:
|
||||||
|
|
@ -522,6 +522,10 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
|
||||||
of hintMin..hintMax:
|
of hintMin..hintMax:
|
||||||
sev = Severity.Hint
|
sev = Severity.Hint
|
||||||
ignoreMsg = not conf.hasHint(msg)
|
ignoreMsg = not conf.hasHint(msg)
|
||||||
|
if msg in conf.warningAsErrors:
|
||||||
|
ignoreMsg = false
|
||||||
|
title = ErrorTitle
|
||||||
|
else:
|
||||||
title = HintTitle
|
title = HintTitle
|
||||||
color = HintColor
|
color = HintColor
|
||||||
inc(conf.hintCounter)
|
inc(conf.hintCounter)
|
||||||
|
|
|
||||||
|
|
@ -352,6 +352,7 @@ proc processNote(c: PContext, n: PNode) =
|
||||||
of wHint: handleNote(hintMin .. hintMax, c.config.notes)
|
of wHint: handleNote(hintMin .. hintMax, c.config.notes)
|
||||||
of wWarning: handleNote(warnMin .. warnMax, c.config.notes)
|
of wWarning: handleNote(warnMin .. warnMax, c.config.notes)
|
||||||
of wWarningAsError: handleNote(warnMin .. warnMax, c.config.warningAsErrors)
|
of wWarningAsError: handleNote(warnMin .. warnMax, c.config.warningAsErrors)
|
||||||
|
of wHintAsError: handleNote(hintMin .. hintMax, c.config.warningAsErrors)
|
||||||
else: invalidPragma(c, n)
|
else: invalidPragma(c, n)
|
||||||
else: invalidPragma(c, n)
|
else: invalidPragma(c, n)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,10 @@ type
|
||||||
wNosinks = "nosinks", wMerge = "merge", wLib = "lib", wDynlib = "dynlib",
|
wNosinks = "nosinks", wMerge = "merge", wLib = "lib", wDynlib = "dynlib",
|
||||||
wCompilerProc = "compilerproc", wCore = "core", wProcVar = "procvar",
|
wCompilerProc = "compilerproc", wCore = "core", wProcVar = "procvar",
|
||||||
wBase = "base", wUsed = "used", wFatal = "fatal", wError = "error", wWarning = "warning",
|
wBase = "base", wUsed = "used", wFatal = "fatal", wError = "error", wWarning = "warning",
|
||||||
wHint = "hint", wWarningAsError = "warningAsError", wLine = "line", wPush = "push",
|
wHint = "hint",
|
||||||
|
wWarningAsError = "warningAsError",
|
||||||
|
wHintAsError = "hintAsError",
|
||||||
|
wLine = "line", wPush = "push",
|
||||||
wPop = "pop", wDefine = "define", wUndef = "undef", wLineDir = "lineDir",
|
wPop = "pop", wDefine = "define", wUndef = "undef", wLineDir = "lineDir",
|
||||||
wStackTrace = "stackTrace", wLineTrace = "lineTrace", wLink = "link", wCompile = "compile",
|
wStackTrace = "stackTrace", wLineTrace = "lineTrace", wLink = "link", wCompile = "compile",
|
||||||
wLinksys = "linksys", wDeprecated = "deprecated", wVarargs = "varargs", wCallconv = "callconv",
|
wLinksys = "linksys", wDeprecated = "deprecated", wVarargs = "varargs", wCallconv = "callconv",
|
||||||
|
|
|
||||||
|
|
@ -41,8 +41,8 @@ Advanced options:
|
||||||
--warning[X]:on|off turn specific warning X on|off
|
--warning[X]:on|off turn specific warning X on|off
|
||||||
--hints:on|off|list turn all hints on|off or list all available
|
--hints:on|off|list turn all hints on|off or list all available
|
||||||
--hint[X]:on|off turn specific hint X on|off
|
--hint[X]:on|off turn specific hint X on|off
|
||||||
--warningAsError[X]:on|off
|
--warningAsError[X]:on|off turn specific warning X into an error on|off
|
||||||
turn specific warning X into an error on|off
|
--hintAsError[X]:on|off turn specific hint X into an error on|off
|
||||||
--styleCheck:off|hint|error
|
--styleCheck:off|hint|error
|
||||||
produce hints or errors for Nim identifiers that
|
produce hints or errors for Nim identifiers that
|
||||||
do not adhere to Nim's official style guide
|
do not adhere to Nim's official style guide
|
||||||
|
|
|
||||||
35
tests/misc/twarningaserror.nim
Normal file
35
tests/misc/twarningaserror.nim
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
discard """
|
||||||
|
joinable: false
|
||||||
|
"""
|
||||||
|
|
||||||
|
#[
|
||||||
|
tests: hintAsError, warningAsError
|
||||||
|
]#
|
||||||
|
|
||||||
|
template fn1 =
|
||||||
|
{.hintAsError[ConvFromXtoItselfNotNeeded]:on.}
|
||||||
|
proc fn(a: string) = discard a.string
|
||||||
|
{.hintAsError[ConvFromXtoItselfNotNeeded]:off.}
|
||||||
|
|
||||||
|
template fn2 =
|
||||||
|
{.hintAsError[ConvFromXtoItselfNotNeeded]:on.}
|
||||||
|
proc fn(a: string) = discard a
|
||||||
|
{.hintAsError[ConvFromXtoItselfNotNeeded]:off.}
|
||||||
|
|
||||||
|
template gn1 =
|
||||||
|
{.warningAsError[ProveInit]:on.}
|
||||||
|
proc fn(): var int = discard
|
||||||
|
discard fn()
|
||||||
|
{.warningAsError[ProveInit]:off.}
|
||||||
|
|
||||||
|
template gn2 =
|
||||||
|
{.warningAsError[ProveInit]:on.}
|
||||||
|
proc fn(): int = discard
|
||||||
|
discard fn()
|
||||||
|
{.warningAsError[ProveInit]:off.}
|
||||||
|
|
||||||
|
doAssert not compiles(fn1())
|
||||||
|
doAssert compiles(fn2())
|
||||||
|
|
||||||
|
doAssert not compiles(gn1())
|
||||||
|
doAssert compiles(gn2())
|
||||||
Loading…
Add table
Add a link
Reference in a new issue