Skip to content

Commit f56568d

Browse files
authored
fixes address of sink parameters (#24924)
In `semExprWithType`: `if result.typ.kind in {tyVar, tyLent}: result = newDeref(result)` derefed `var`/`lent`. Since it is not done for `sink`, we need to skip `tySink` in the corresponding procs
1 parent b5b7a12 commit f56568d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/magicsys.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,4 @@ proc makeAddr*(n: PNode; idgen: IdGenerator): PNode =
166166
result = n
167167
else:
168168
result = newTree(nkHiddenAddr, n)
169-
result.typ() = makePtrType(n.typ, idgen)
169+
result.typ() = makePtrType(n.typ.skipTypes({tySink}), idgen)

compiler/semmagic.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ proc semAddr(c: PContext; n: PNode): PNode =
3838
if isAssignable(c, x) notin {arLValue, arLocalLValue, arAddressableConst, arLentValue}:
3939
localError(c.config, n.info, errExprHasNoAddress)
4040
result.add x
41-
result.typ() = makePtrType(c, x.typ)
41+
result.typ() = makePtrType(c, x.typ.skipTypes({tySink}))
4242

4343
proc semTypeOf(c: PContext; n: PNode): PNode =
4444
var m = BiggestInt 1 # typeOfIter

tests/destructor/tsink.nim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,11 @@ block: # bug #24175
6868
static:
6969
foo()
7070
foo()
71+
72+
proc create(value: sink int): ptr int =
73+
let s = addr value
74+
result = addr value
75+
result = s
76+
77+
78+
let xxx = create(12)

0 commit comments

Comments
 (0)