From 11ead19bc1c811f8733637d8be44833803d0a0af Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 30 Aug 2024 22:08:59 +0800 Subject: [PATCH] fixes #24034; fixes lent types after taking implicit address (#24035) fixes #24034 --- compiler/semexprs.nim | 2 ++ tests/lent/tlent_from_var.nim | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 91e318a6389dd..1b73b9b20ded6 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -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.} = diff --git a/tests/lent/tlent_from_var.nim b/tests/lent/tlent_from_var.nim index 8cf65e2860ad3..1fb3d0c17c058 100644 --- a/tests/lent/tlent_from_var.nim +++ b/tests/lent/tlent_from_var.nim @@ -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