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

* fix #22448

* add test
This commit is contained in:
Pylgos
2023-08-12 01:23:09 +09:00
committed by GitHub
parent 469c9cfab4
commit 48da472dd2
2 changed files with 20 additions and 0 deletions

View File

@@ -353,6 +353,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:
@@ -363,6 +368,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;;*
"""