fixes #24034; fixes lent types after taking implicit address (#24035)

fixes #24034

(cherry picked from commit 11ead19bc1)
This commit is contained in:
ringabout
2024-08-30 22:08:59 +08:00
committed by narimiran
parent 0e2b34ce35
commit 8859f1ddf7
2 changed files with 21 additions and 0 deletions

View File

@@ -1850,6 +1850,8 @@ proc takeImplicitAddr(c: PContext, n: PNode; isLent: bool): PNode =
else:
localError(c.config, n.info, errExprHasNoAddress)
result = newNodeIT(nkHiddenAddr, n.info, if n.typ.kind in {tyVar, tyLent}: n.typ else: makePtrType(c, n.typ))
if n.typ.kind in {tyVar, tyLent}:
n.typ = n.typ.elementType
result.add(n)
proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =

View File

@@ -50,3 +50,22 @@ template get*[T: not void](self: Opt[T]): T = self.value()
method connect*(
self: Opt[(int, int)]) =
discard self.get()[0]
block: # bug #24034
type T = object
v: array[100, byte]
iterator pairs(t: T): (int, lent array[100, byte]) =
yield (0, t.v)
block:
for a, b in default(T):
doAssert a == 0
doAssert b.len == 100
block:
for (a, b) in pairs(default(T)):
doAssert a == 0
doAssert b.len == 100