From f1ff20a18c381435875174e2bee4f9222cd0b8af Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 16 Mar 2023 21:07:54 +0800 Subject: [PATCH] fixes #19857; Exception raised in closure may be "skipped" in ORC (#21530) fixes #19857; Exception raised in closure may be "skipped" --- compiler/ccgcalls.nim | 1 + tests/arc/tarcmisc.nim | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 48e7fd2901482..65c814fb90c96 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -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) diff --git a/tests/arc/tarcmisc.nim b/tests/arc/tarcmisc.nim index a03da62118f6e..1ae1782a47f86 100644 --- a/tests/arc/tarcmisc.nim +++ b/tests/arc/tarcmisc.nim @@ -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()