fixes #25553; Invalid codegen for accessing tuple in array (#25555)

fixes #25553
This commit is contained in:
ringabout
2026-03-01 05:51:38 +08:00
committed by GitHub
parent a2db2af5b6
commit 4566ffaca9
2 changed files with 17 additions and 2 deletions

View File

@@ -2186,9 +2186,9 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate,
result.typ = errorType(c)
else:
result.typ = f.skipTypes({tySink})
# keep varness
# keep varness, but don't wrap lent types with var
if arg.typ != nil and arg.typ.kind == tyVar:
result.typ = toVar(result.typ, tyVar, c.idgen)
result.typ = toVar(result.typ.skipTypes({tyLent}), tyVar, c.idgen)
# copy the tfVarIsPtr flag
result.typ.flags = arg.typ.flags
else:

View File

@@ -23,3 +23,18 @@ proc varProc(x: var int) =
doAssert: not compiles(test_lent(x) = 1)
doAssert: not compiles(varProc(test_lent(x)))
type X = tuple[a: int, b: int]
type ArrayBuf*[N: static int, T] = object
buf*: array[N, T]
var v: ArrayBuf[32, X]
# proc `[]`*[N, T](b: var ArrayBuf[N, T], i: BackwardsIndex): lent T = # works
# b.buf[i]
template `[]`*[N, T](b: var ArrayBuf[N, T], i: BackwardsIndex): lent T =
b.buf[i]
doAssert $v[^4] == "(a: 0, b: 0)"