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
This commit is contained in:
ringabout
2025-05-01 13:49:46 +08:00
committed by GitHub
parent b5b7a127fd
commit f56568d851
3 changed files with 10 additions and 2 deletions

View File

@@ -166,4 +166,4 @@ proc makeAddr*(n: PNode; idgen: IdGenerator): PNode =
result = n
else:
result = newTree(nkHiddenAddr, n)
result.typ() = makePtrType(n.typ, idgen)
result.typ() = makePtrType(n.typ.skipTypes({tySink}), idgen)

View File

@@ -38,7 +38,7 @@ proc semAddr(c: PContext; n: PNode): PNode =
if isAssignable(c, x) notin {arLValue, arLocalLValue, arAddressableConst, arLentValue}:
localError(c.config, n.info, errExprHasNoAddress)
result.add x
result.typ() = makePtrType(c, x.typ)
result.typ() = makePtrType(c, x.typ.skipTypes({tySink}))
proc semTypeOf(c: PContext; n: PNode): PNode =
var m = BiggestInt 1 # typeOfIter

View File

@@ -68,3 +68,11 @@ block: # bug #24175
static:
foo()
foo()
proc create(value: sink int): ptr int =
let s = addr value
result = addr value
result = s
let xxx = create(12)