Skip to content

Commit 638a8bf

Browse files
authored
fixes #24974; SIGSEGV when raising Defect/doAssert (#24985)
fixes #24974 requires `result` initializations when encountering unreachable code (e.g. `quit`)
1 parent ffb993d commit 638a8bf

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

compiler/cgen.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,9 @@ proc allPathsAsgnResult(p: BProc; n: PNode): InitResultEnum =
12341234
else:
12351235
allPathsInBranch(n[i].lastSon)
12361236
of nkCallKinds:
1237-
if canRaiseDisp(p, n[0]):
1237+
if canRaiseDisp(p, n[0]) or
1238+
(n[0].kind == nkSym and sfNoReturn in n[0].sym.flags):
1239+
# requires initializations when encountering unreachable code
12381240
result = InitRequired
12391241
else:
12401242
for i in 0..<n.safeLen:

tests/errmsgs/t24974.nim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
discard """
2+
exitcode: 1
3+
output: '''
4+
t24974.nim(22) t24974
5+
t24974.nim(19) d
6+
t24974.nim(16) s
7+
assertions.nim(41) failedAssertImpl
8+
assertions.nim(36) raiseAssert
9+
fatal.nim(53) sysFatal
10+
Error: unhandled exception: t24974.nim(16, 26) `false` [AssertionDefect]
11+
'''
12+
"""
13+
14+
15+
type B = seq[array[1, byte]]
16+
proc s(_: var B): bool = doAssert false
17+
proc d(): B =
18+
var k: B
19+
if s(k): discard
20+
quit 0
21+
k
22+
for _ in [0]: discard d()

0 commit comments

Comments
 (0)