Skip to content

Commit

Permalink
fixes #24034; fixes lent types after taking implicit address (#24035)
Browse files Browse the repository at this point in the history
fixes #24034
  • Loading branch information
ringabout authored Aug 30, 2024
1 parent aa0d8e9 commit 11ead19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,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.} =
Expand Down
19 changes: 19 additions & 0 deletions tests/lent/tlent_from_var.nim
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,22 @@ block: # bug #23454
for (a, _) in instance:
case a
of A: discard

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

0 comments on commit 11ead19

Please sign in to comment.