diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-01-20 01:49:59 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-20 10:49:59 +0100 |
commit | 4fc7fcb775140dc774a713063917fbf7d1392bdf (patch) | |
tree | ffb29f080816cc85e7a47a96cde8e79945d023a8 /compiler | |
parent | 2bedb0fe2c38424a53ec7376c05db09090af9f93 (diff) | |
download | Nim-4fc7fcb775140dc774a713063917fbf7d1392bdf.tar.gz |
`--hintAsError` (#16763)
* --hintAsError * add test, changelog * condsyms
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/commands.nim | 10 | ||||
-rw-r--r-- | compiler/condsyms.nim | 1 | ||||
-rw-r--r-- | compiler/msgs.nim | 8 | ||||
-rw-r--r-- | compiler/pragmas.nim | 1 | ||||
-rw-r--r-- | compiler/wordrecg.nim | 5 |
5 files changed, 18 insertions, 7 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim index bc1a63cc4..0c835a2f7 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -191,7 +191,8 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass, if i == arg.len: discard elif i < arg.len and (arg[i] in {':', '='}): inc(i) 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) if x != errUnknown: n = TNoteKind(x) else: localError(conf, info, "unknown hint: " & id) @@ -209,13 +210,13 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass, incl(conf.modifiedyNotes, n) case val of "on": - if state == wWarningAsError: - incl(conf.warningAsErrors, n) + if state in {wWarningAsError, wHintAsError}: + incl(conf.warningAsErrors, n) # xxx rename warningAsErrors to noteAsErrors else: incl(conf.notes, n) incl(conf.mainPackageNotes, n) of "off": - if state == wWarningAsError: + if state in {wWarningAsError, wHintAsError}: excl(conf.warningAsErrors, n) else: 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 "hint": processSpecificNote(arg, wHint, pass, info, switch, conf) of "warningaserror": processSpecificNote(arg, wWarningAsError, pass, info, switch, conf) + of "hintaserror": processSpecificNote(arg, wHintAsError, pass, info, switch, conf) of "hints": if processOnOffSwitchOrList(conf, {optHints}, arg, pass, info): listHints(conf) of "threadanalysis": processOnOffSwitchG(conf, {optThreadAnalysis}, arg, pass, info) diff --git a/compiler/condsyms.nim b/compiler/condsyms.nim index 55f2b4a0f..a6ad45436 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -124,3 +124,4 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimHasCastPragmaBlocks") defineSymbol("nimHasDeclaredLocs") defineSymbol("nimHasJsBigIntBackend") + defineSymbol("nimHasHintAsError") diff --git a/compiler/msgs.nim b/compiler/msgs.nim index afb51da09..442695ea1 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -413,7 +413,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): + (msg in warnMin..hintMax and msg in conf.warningAsErrors): inc(conf.errorCounter) conf.exitcode = 1'i8 if conf.errorCounter >= conf.errorMax: @@ -522,7 +522,11 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string, of hintMin..hintMax: sev = Severity.Hint ignoreMsg = not conf.hasHint(msg) - title = HintTitle + if msg in conf.warningAsErrors: + ignoreMsg = false + title = ErrorTitle + else: + title = HintTitle color = HintColor inc(conf.hintCounter) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 1404959c6..c8aee3327 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -352,6 +352,7 @@ proc processNote(c: PContext, n: PNode) = of wHint: handleNote(hintMin .. hintMax, c.config.notes) of wWarning: handleNote(warnMin .. warnMax, c.config.notes) of wWarningAsError: handleNote(warnMin .. warnMax, c.config.warningAsErrors) + of wHintAsError: handleNote(hintMin .. hintMax, c.config.warningAsErrors) else: invalidPragma(c, n) else: invalidPragma(c, n) diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index 170d04df1..ad529f437 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -49,7 +49,10 @@ type wNosinks = "nosinks", wMerge = "merge", wLib = "lib", wDynlib = "dynlib", wCompilerProc = "compilerproc", wCore = "core", wProcVar = "procvar", 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", wStackTrace = "stackTrace", wLineTrace = "lineTrace", wLink = "link", wCompile = "compile", wLinksys = "linksys", wDeprecated = "deprecated", wVarargs = "varargs", wCallconv = "callconv", |