Fix handling of reraise in effect tracking (#10582)
This is the MVP in order not to get a completely useless error message from the compiler. Fixes #10579
This commit is contained in:
parent
c95616f6ee
commit
f23b0a7dc8
2 changed files with 23 additions and 5 deletions
|
|
@ -721,11 +721,17 @@ proc track(tracked: PEffects, n: PNode) =
|
||||||
of nkSym:
|
of nkSym:
|
||||||
useVar(tracked, n)
|
useVar(tracked, n)
|
||||||
of nkRaiseStmt:
|
of nkRaiseStmt:
|
||||||
n.sons[0].info = n.info
|
if n[0].kind != nkEmpty:
|
||||||
#throws(tracked.exc, n.sons[0])
|
n.sons[0].info = n.info
|
||||||
addEffect(tracked, n.sons[0], useLineInfo=false)
|
#throws(tracked.exc, n.sons[0])
|
||||||
for i in 0 ..< safeLen(n):
|
addEffect(tracked, n.sons[0], useLineInfo=false)
|
||||||
track(tracked, n.sons[i])
|
for i in 0 ..< safeLen(n):
|
||||||
|
track(tracked, n.sons[i])
|
||||||
|
else:
|
||||||
|
# A `raise` with no arguments means we're going to re-raise the exception
|
||||||
|
# being handled or, if outside of an `except` block, a `ReraiseError`.
|
||||||
|
# Here we add a `Exception` tag in order to cover both the cases.
|
||||||
|
addEffect(tracked, createRaise(tracked.graph, n))
|
||||||
of nkCallKinds:
|
of nkCallKinds:
|
||||||
if getConstExpr(tracked.owner_module, n, tracked.graph) != nil:
|
if getConstExpr(tracked.owner_module, n, tracked.graph) != nil:
|
||||||
return
|
return
|
||||||
|
|
|
||||||
12
tests/effects/teffects8.nim
Normal file
12
tests/effects/teffects8.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
discard """
|
||||||
|
errormsg: "can raise an unlisted exception: Exception"
|
||||||
|
line: 10
|
||||||
|
"""
|
||||||
|
|
||||||
|
proc foo() {.raises: [].} =
|
||||||
|
try:
|
||||||
|
discard
|
||||||
|
except ValueError:
|
||||||
|
raise
|
||||||
|
|
||||||
|
foo()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue