Skip to content

Commit

Permalink
fix #18971 (#19070) [backport:1.6]
Browse files Browse the repository at this point in the history
since the example code return value from global variable, instead
of first argument, the `n.len` is 1 which causes compiler crashes.

(cherry picked from commit f755e45)
  • Loading branch information
derekdai authored and narimiran committed Nov 3, 2021
1 parent 1ac029c commit 97286db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/varpartitions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ proc destMightOwn(c: var Partitions; dest: var VarIndex; n: PNode) =
# calls do construct, what we construct must be destroyed,
# so dest cannot be a cursor:
dest.flags.incl ownsData
elif n.typ.kind in {tyLent, tyVar}:
elif n.typ.kind in {tyLent, tyVar} and n.len > 1:
# we know the result is derived from the first argument:
var roots: seq[(PSym, int)]
allRoots(n[1], roots, RootEscapes)
Expand Down
10 changes: 10 additions & 0 deletions tests/arc/t18971.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
discard """
cmd: "nim c --gc:arc $file"
"""

type MyObj = ref object

var o = MyObj()
proc x: var MyObj = o

var o2 = x()

0 comments on commit 97286db

Please sign in to comment.