Skip to content

Commit

Permalink
fixes nim-lang#19857; Exception raised in closure may be "skipped" in…
Browse files Browse the repository at this point in the history
… ORC (nim-lang#21530)

fixes nim-lang#19857; Exception raised in closure may be "skipped"
  • Loading branch information
ringabout authored and capocasa committed Mar 31, 2023
1 parent 2ae1288 commit f1ff20a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/ccgcalls.nim
Expand Up @@ -475,6 +475,7 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) =
discard "resetLoc(p, d)"
pl.add(addrLoc(p.config, d))
genCallPattern()
if canRaise: raiseExit(p)
else:
var tmp: TLoc
getTemp(p, typ[0], tmp, needsInit=true)
Expand Down
39 changes: 39 additions & 0 deletions tests/arc/tarcmisc.nim
Expand Up @@ -558,3 +558,42 @@ block:
doAssert y.id == 778
doAssert x[].id == 778
main()

block: # bug #19857
type
ValueKind = enum VNull, VFloat, VObject # need 3 elements. Cannot remove VNull or VObject

Value = object
case kind: ValueKind
of VFloat: fnum: float
of VObject: tab: Table[int, int] # OrderedTable[T, U] also makes it fail.
# "simpler" types also work though
else: discard # VNull can be like this, but VObject must be filled

# required. Pure proc works
FormulaNode = proc(c: OrderedTable[string, int]): Value

proc toF(v: Value): float =
doAssert v.kind == VFloat
case v.kind
of VFloat: result = v.fnum
else: discard


proc foo() =
let fuck = initOrderedTable[string, int]()
proc cb(fuck: OrderedTable[string, int]): Value =
# works:
#result = Value(kind: VFloat, fnum: fuck["field_that_does_not_exist"].float)
# broken:
discard "actuall runs!"
let t = fuck["field_that_does_not_exist"]
echo "never runs, but we crash after! ", t

doAssertRaises(KeyError):
let fn = FormulaNode(cb)
let v = fn(fuck)
#echo v
let res = v.toF()

foo()

0 comments on commit f1ff20a

Please sign in to comment.