fix #22448 Remove structuredErrorHook temporary in tryConstExpr (#22450)

* fix #22448

* add test

(cherry picked from commit 48da472dd2)
This commit is contained in:
Pylgos
2023-08-12 01:23:09 +09:00
committed by narimiran
parent 6f00b46c4b
commit 814e929eeb
2 changed files with 20 additions and 0 deletions

View File

@@ -400,6 +400,11 @@ proc tryConstExpr(c: PContext, n: PNode; expectedType: PType = nil): PNode =
c.config.m.errorOutputs = {}
c.config.errorMax = high(int) # `setErrorMaxHighMaybe` not appropriate here
when defined(nimsuggest):
# Remove the error hook so nimsuggest doesn't report errors there
let tempHook = c.graph.config.structuredErrorHook
c.graph.config.structuredErrorHook = nil
try:
result = evalConstExpr(c.module, c.idgen, c.graph, e)
if result == nil or result.kind == nkEmpty:
@@ -410,6 +415,10 @@ proc tryConstExpr(c: PContext, n: PNode; expectedType: PType = nil): PNode =
except ERecoverableError:
result = nil
when defined(nimsuggest):
# Restore the error hook
c.graph.config.structuredErrorHook = tempHook
c.config.errorCounter = oldErrorCount
c.config.errorMax = oldErrorMax
c.config.m.errorOutputs = oldErrorOutputs

View File

@@ -0,0 +1,11 @@
proc fn(a: static float) = discard
proc fn(a: int) = discard
let x = 1
fn(x)
discard """
$nimsuggest --tester --v3 $file
>chk $file
chk;;skUnknown;;;;Hint;;*
"""