Skip to content

Commit 00ce35f

Browse files
committed
fix #18971
since the example code return value from global variable, instead of first argument, the `n.len` is 1 which causes compiler crashes.
1 parent cfdac66 commit 00ce35f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

compiler/varpartitions.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ proc destMightOwn(c: var Partitions; dest: var VarIndex; n: PNode) =
479479
# calls do construct, what we construct must be destroyed,
480480
# so dest cannot be a cursor:
481481
dest.flags.incl ownsData
482-
elif n.typ.kind in {tyLent, tyVar}:
482+
elif n.typ.kind in {tyLent, tyVar} and n.len > 1:
483483
# we know the result is derived from the first argument:
484484
var roots: seq[(PSym, int)]
485485
allRoots(n[1], roots, RootEscapes)

tests/arc/t18971.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
discard """
2+
cmd: "nim c --gc:arc $file"
3+
"""
4+
5+
type MyObj = ref object
6+
7+
var o = MyObj()
8+
proc x: var MyObj = o
9+
10+
var o2 = x()

0 commit comments

Comments
 (0)