From 7fdbdb2f20a9d43e62afac8c32dfd3a3e39d3149 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 10 Jun 2025 20:12:12 +0800 Subject: [PATCH] fixes #24974; SIGSEGV when raising Defect/doAssert (#24985) fixes #24974 requires `result` initializations when encountering unreachable code (e.g. `quit`) (cherry picked from commit 638a8bf84d35c6be54cd7e4b4642ce77ae83da39) --- compiler/cgen.nim | 4 +++- tests/errmsgs/t24974.nim | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/errmsgs/t24974.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index ffc2b7ea27..05c63c4680 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1150,7 +1150,9 @@ proc allPathsAsgnResult(p: BProc; n: PNode): InitResultEnum = else: allPathsInBranch(n[i].lastSon) of nkCallKinds: - if canRaiseDisp(p, n[0]): + if canRaiseDisp(p, n[0]) or + (n[0].kind == nkSym and sfNoReturn in n[0].sym.flags): + # requires initializations when encountering unreachable code result = InitRequired else: for i in 0..