From 48da472dd2e625d2d794907afd33a4a153fa2dc1 Mon Sep 17 00:00:00 2001 From: Pylgos <43234674+Pylgos@users.noreply.github.com> Date: Sat, 12 Aug 2023 01:23:09 +0900 Subject: [PATCH] fix #22448 Remove `structuredErrorHook` temporary in `tryConstExpr` (#22450) * fix #22448 * add test --- compiler/sem.nim | 9 +++++++++ nimsuggest/tests/t22448.nim | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 nimsuggest/tests/t22448.nim diff --git a/compiler/sem.nim b/compiler/sem.nim index f19f273b5d..f69e7a69d0 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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 diff --git a/nimsuggest/tests/t22448.nim b/nimsuggest/tests/t22448.nim new file mode 100644 index 0000000000..8664bbbc3c --- /dev/null +++ b/nimsuggest/tests/t22448.nim @@ -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;;* +"""