mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fixes #24974
requires `result` initializations when encountering unreachable code
(e.g. `quit`)
(cherry picked from commit 638a8bf84d)
This commit is contained in:
@@ -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..<n.safeLen:
|
||||
|
||||
22
tests/errmsgs/t24974.nim
Normal file
22
tests/errmsgs/t24974.nim
Normal file
@@ -0,0 +1,22 @@
|
||||
discard """
|
||||
exitcode: 1
|
||||
output: '''
|
||||
t24974.nim(22) t24974
|
||||
t24974.nim(19) d
|
||||
t24974.nim(16) s
|
||||
assertions.nim(41) failedAssertImpl
|
||||
assertions.nim(36) raiseAssert
|
||||
fatal.nim(53) sysFatal
|
||||
Error: unhandled exception: t24974.nim(16, 26) `false` [AssertionDefect]
|
||||
'''
|
||||
"""
|
||||
|
||||
|
||||
type B = seq[array[1, byte]]
|
||||
proc s(_: var B): bool = doAssert false
|
||||
proc d(): B =
|
||||
var k: B
|
||||
if s(k): discard
|
||||
quit 0
|
||||
k
|
||||
for _ in [0]: discard d()
|
||||
Reference in New Issue
Block a user