mirror of
https://github.com/nim-lang/Nim.git
synced 2026-09-17 02:32:11 +00:00
fixes #26119
This commit is contained in:
@@ -787,6 +787,12 @@ template handleNestedTempl(n, processCall: untyped, willProduceStmt = false,
|
||||
result = nil
|
||||
assert(false)
|
||||
|
||||
if willProduceStmt:
|
||||
# The value is now produced by statements in the branches. Keeping the
|
||||
# control-flow node's expression type would make code generators allocate
|
||||
# a second, unused destination for it.
|
||||
result.typ = nil
|
||||
|
||||
proc pRaiseStmt(n: PNode, c: var Con; s: var Scope): PNode =
|
||||
if optOwnedRefs in c.graph.config.globalOptions and n[0].kind != nkEmpty:
|
||||
if n[0].kind in nkCallKinds:
|
||||
|
||||
20
tests/ccgbugs/t26119.nim
Normal file
20
tests/ccgbugs/t26119.nim
Normal file
@@ -0,0 +1,20 @@
|
||||
discard """
|
||||
targets: "c cpp"
|
||||
matrix: "--mm:refc; --mm:orc"
|
||||
ccodeCheck: "\\i !@('W T' \\d+ '_;')"
|
||||
"""
|
||||
|
||||
type W {.exportc.} = object
|
||||
data: array[1000, byte]
|
||||
items: seq[int]
|
||||
|
||||
# bug #26119: assigning a try expression directly to the result must not leave
|
||||
# an unused temporary of the result type in the generated procedure.
|
||||
proc y(): W {.exportc.} =
|
||||
try:
|
||||
default(W)
|
||||
except CatchableError:
|
||||
default(W)
|
||||
|
||||
var v = y()
|
||||
doAssert v.data[0] == 0 and v.items.len == 0
|
||||
Reference in New Issue
Block a user