Skip to content

Commit 3d692d0

Browse files
authored
fixes a long-standing ARC bug (#20849)
* fixes an ARC bug * add a testcase
1 parent 4a3be7e commit 3d692d0

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

compiler/aliasanalysis.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ proc aliases*(obj, field: PNode): AliasKind =
6363
# x.f -> x: false
6464
# x.f -> x.f: true
6565
# x.f -> x.v: false
66+
# x -> x[]: true
67+
# x[] -> x: false
6668
# x -> x[0]: true
6769
# x[0] -> x: false
6870
# x[0] -> x[0]: true
@@ -76,11 +78,11 @@ proc aliases*(obj, field: PNode): AliasKind =
7678
var n = n
7779
while true:
7880
case n.kind
79-
of PathKinds0 - {nkDotExpr, nkBracketExpr}:
81+
of PathKinds0 - {nkDotExpr, nkBracketExpr, nkDerefExpr, nkHiddenDeref}:
8082
n = n[0]
8183
of PathKinds1:
8284
n = n[1]
83-
of nkDotExpr, nkBracketExpr:
85+
of nkDotExpr, nkBracketExpr, nkDerefExpr, nkHiddenDeref:
8486
result.add n
8587
n = n[0]
8688
of nkSym:
@@ -114,6 +116,8 @@ proc aliases*(obj, field: PNode): AliasKind =
114116
if currFieldPath.sym != currObjPath.sym: return no
115117
of nkDotExpr:
116118
if currFieldPath[1].sym != currObjPath[1].sym: return no
119+
of nkDerefExpr, nkHiddenDeref:
120+
discard
117121
of nkBracketExpr:
118122
if currFieldPath[1].kind in nkLiterals and currObjPath[1].kind in nkLiterals:
119123
if currFieldPath[1].intVal != currObjPath[1].intVal:

tests/arc/tarcmisc.nim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,3 +546,15 @@ proc fooz(sec: var InputSectionBase) =
546546
var sec = create(InputSection)
547547
sec[] = InputSection(relocations: newSeq[int]())
548548
fooz sec[]
549+
550+
block:
551+
type
552+
Data = ref object
553+
id: int
554+
proc main =
555+
var x = Data(id: 99)
556+
var y = x
557+
x[] = Data(id: 778)[]
558+
doAssert y.id == 778
559+
doAssert x[].id == 778
560+
main()

0 commit comments

Comments
 (0)