Skip to content

Commit

Permalink
fixes #12827 (#12829) [backport]
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldome authored and Araq committed Dec 10, 2019
1 parent c282cee commit 13d232e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -945,11 +945,12 @@ proc allPathsAsgnResult(n: PNode): InitResultEnum =
# assignment this is not good enough! The only pattern we allow for
# is 'finally: result = x'
result = InitSkippable
for it in n:
if it.kind == nkFinally:
result = allPathsAsgnResult(it.lastSon)
allPathsInBranch(n[0])
for i in 1..<n.len:
if n[i].kind == nkFinally:
result = allPathsAsgnResult(n[i].lastSon)
else:
allPathsInBranch(it.lastSon)
allPathsInBranch(n[i].lastSon)
else:
for i in 0..<n.safeLen:
allPathsInBranch(n[i])
Expand Down
17 changes: 17 additions & 0 deletions tests/destructor/tnewruntime_misc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ axc
0 new: 0
...
destroying GenericObj[T] GenericObj[system.int]
test
'''
"""

Expand Down Expand Up @@ -117,3 +118,19 @@ proc main12() =
echo "..."

main12()

#####################################################################
## bug #12827
type
MyObject = object
x: string
y: seq[string]
needs_ref: ref int

proc xx(xml: string): MyObject =
let stream = xml
result.x = xml
defer: echo stream


discard xx("test")

0 comments on commit 13d232e

Please sign in to comment.