summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-08-20 04:24:09 +0800
committerGitHub <noreply@github.com>2022-08-19 16:24:09 -0400
commit641381e3d47afba95f99efc77bb9a5ed65d07b3a (patch)
tree00b9392f142af032e92337cd3cc84cc127084003
parentc9c1c97f1ec394cc5e7638825d806413b874c080 (diff)
downloadNim-641381e3d47afba95f99efc77bb9a5ed65d07b3a.tar.gz
fixes #20149; fixes #16762; hintAsError and warningAsError now ignore foreign packages (#20151)
* fixes #20149;  hintAsError/warningAsError ignores foreign packages

* add changelog

* fixes the test

* remove

* fixes tests again

* fix

* I'm careless

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
-rw-r--r--changelog.md2
-rw-r--r--compiler/msgs.nim12
-rw-r--r--tests/misc/m20149.nim2
-rw-r--r--tests/misc/trunner.nim6
4 files changed, 14 insertions, 8 deletions
diff --git a/changelog.md b/changelog.md
index 98345709b..d574d1074 100644
--- a/changelog.md
+++ b/changelog.md
@@ -127,7 +127,7 @@
 - `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`,
   without requiring `-d:nimVersion140` which is now a noop.
 
-- `--styleCheck` now only applies to the current package.
+- `--styleCheck`, `--hintAsError` and `--warningAsError` now only applies to the current package.
 
 - The switch `--nimMainPrefix:prefix` has been added to add a prefix to the names of `NimMain` and
   related functions produced on the backend. This prevents conflicts with other Nim
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index ed65e0342..50bd94cda 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -418,12 +418,12 @@ To create a stacktrace, rerun compilation with './koch temp $1 <file>', see $2 f
           [conf.command, "intern.html#debugging-the-compiler".createDocLink], conf.unitSep)
   quit 1
 
-proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string) =
+proc handleError(conf: ConfigRef; msg: TMsgKind, eh: TErrorHandling, s: string, ignoreMsg: bool) =
   if msg in fatalMsgs:
     if conf.cmd == cmdIdeTools: log(s)
     quit(conf, msg)
   if msg >= errMin and msg <= errMax or
-      (msg in warnMin..hintMax and msg in conf.warningAsErrors):
+      (msg in warnMin..hintMax and msg in conf.warningAsErrors and not ignoreMsg):
     inc(conf.errorCounter)
     conf.exitcode = 1'i8
     if conf.errorCounter >= conf.errorMax:
@@ -531,8 +531,7 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
   of warnMin..warnMax:
     sev = Severity.Warning
     ignoreMsg = not conf.hasWarn(msg)
-    if msg in conf.warningAsErrors:
-      ignoreMsg = false
+    if not ignoreMsg and msg in conf.warningAsErrors:
       title = ErrorTitle
     else:
       title = WarningTitle
@@ -542,8 +541,7 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
   of hintMin..hintMax:
     sev = Severity.Hint
     ignoreMsg = not conf.hasHint(msg)
-    if msg in conf.warningAsErrors:
-      ignoreMsg = false
+    if not ignoreMsg and msg in conf.warningAsErrors:
       title = ErrorTitle
     else:
       title = HintTitle
@@ -569,7 +567,7 @@ proc liMessage*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
             " compiler msg initiated here", KindColor,
             KindFormat % $hintMsgOrigin,
             resetStyle, conf.unitSep)
-  handleError(conf, msg, eh, s)
+  handleError(conf, msg, eh, s, ignoreMsg)
   if msg in fatalMsgs:
     # most likely would have died here but just in case, we restore state
     conf.m.errorOutputs = errorOutputsOld
diff --git a/tests/misc/m20149.nim b/tests/misc/m20149.nim
new file mode 100644
index 000000000..942262a6e
--- /dev/null
+++ b/tests/misc/m20149.nim
@@ -0,0 +1,2 @@
+let x = 12
+echo x
diff --git a/tests/misc/trunner.nim b/tests/misc/trunner.nim
index bc2e872ef..541e3a390 100644
--- a/tests/misc/trunner.nim
+++ b/tests/misc/trunner.nim
@@ -249,12 +249,18 @@ sub/mmain.idx""", context
     let cmd = fmt"{nim} r -b:cpp --hints:off --nimcache:{nimcache} --warningAsError:ProveInit {file}"
     check execCmdEx(cmd) == ("witness\n", 0)
 
+  block: # bug #20149
+    let file = testsDir / "misc/m20149.nim"
+    let cmd = fmt"{nim} r --hints:off --nimcache:{nimcache} --hintAsError:XDeclaredButNotUsed {file}"
+    check execCmdEx(cmd) == ("12\n", 0)
+
   block: # bug #15316
     let file = testsDir / "misc/m15316.nim"
     let cmd = fmt"{nim} check --hints:off --nimcache:{nimcache} {file}"
     check execCmdEx(cmd) == ("m15316.nim(1, 15) Error: expression expected, but found \')\'\nm15316.nim(2, 1) Error: expected: \':\', but got: \'[EOF]\'\nm15316.nim(2, 1) Error: expression expected, but found \'[EOF]\'\nm15316.nim(2, 1) " &
           "Error: expected: \')\', but got: \'[EOF]\'\nError: illformed AST: \n", 1)
 
+
   block: # config.nims, nim.cfg, hintConf, bug #16557
     let cmd = fmt"{nim} r --hint:all:off --hint:conf tests/newconfig/bar/mfoo.nim"
     let (outp, exitCode) = execCmdEx(cmd, options = {poStdErrToStdOut})