Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #23454; IndexDefect thrown when destructuring a lent tuple #23458

Draft
wants to merge 2 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -441,11 +441,20 @@ proc transformYield(c: PTransf, n: PNode): PNode =
let v = newNodeI(nkVarSection, e.info)
v.addVar(tmp, e)

if e.typ.kind == tyPtr: # tyLent
ringabout marked this conversation as resolved.
Show resolved Hide resolved
tmp = newTreeIT(nkHiddenDeref, e.info, e.typ.skipTypes({tyPtr}),
tmp)

result.add transform(c, v)
for i in 0..<c.transCon.forStmt[0].len-1:
let lhs = c.transCon.forStmt[0][i]
let rhs = transform(c, newTupleAccess(c.graph, tmp, i))
result.add(asgnTo(lhs, rhs))
if lhs.typ.kind == tyLent:
ringabout marked this conversation as resolved.
Show resolved Hide resolved
var addrExp = newNodeIT(nkHiddenAddr, rhs.info, makeVarType(rhs.typ.owner, rhs.typ, c.idgen, tyPtr))
addrExp.add(rhs)
result.add(asgnTo(lhs, addrExp))
else:
result.add(asgnTo(lhs, rhs))
else:
for i in 0..<c.transCon.forStmt[0].len-1:
let lhs = c.transCon.forStmt[0][i]
Expand Down
18 changes: 18 additions & 0 deletions tests/lent/tlent_from_var.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,21 @@ template get*[T: not void](self: Opt[T]): T = self.value()
method connect*(
self: Opt[(int, int)]) =
discard self.get()[0]

block: # bug #23454
type
Letter = enum
A

LetterPairs = object
values: seq[(Letter, string)]

iterator items(list: var LetterPairs): lent (Letter, string) =
for item in list.values:
yield item

var instance = LetterPairs(values: @[(A, "foo")])

for (a, _) in instance:
case a
of A: discard