fixes #23321; Error: internal error: openArrayLoc: ref array[0..0, int] (#23548)

fixes #23321

In the function `mapType`, ptrs (tyPtr, tyVar, tyLent, tyRef)
are mapped into ctPtrToArray, the dereference of which is skipped
in the `genref`. We need to skip these ptrs in the function
`genOpenArraySlice`.
This commit is contained in:
ringabout
2024-04-29 22:58:33 +08:00
committed by GitHub
parent 47594eb909
commit d09c3c0f58
2 changed files with 39 additions and 1 deletions

View File

@@ -166,7 +166,10 @@ proc genOpenArraySlice(p: BProc; q: PNode; formalType, destType: PType; prepareF
genBoundsCheck(p, a, b, c)
if prepareForMutation:
linefmt(p, cpsStmts, "#nimPrepareStrMutationV2($1);$n", [byRefLoc(p, a)])
let ty = skipTypes(a.t, abstractVar+{tyPtr})
# bug #23321: In the function mapType, ptrs (tyPtr, tyVar, tyLent, tyRef)
# are mapped into ctPtrToArray, the dereference of which is skipped
# in the `genref`. We need to skip these ptrs here
let ty = skipTypes(a.t, abstractVar+{tyPtr, tyRef})
let dest = getTypeDesc(p.module, destType)
let lengthExpr = "($1)-($2)+1" % [rdLoc(c), rdLoc(b)]
case ty.kind

View File

@@ -48,6 +48,41 @@ proc main =
doAssert testing(mySeq) == mySeq
doAssert testing(mySeq[2..^2]) == mySeq[2..^2]
block: # bug #23321
block:
proc foo(x: openArray[int]) =
doAssert x[0] == 0
var d = new array[1, int]
foo d[].toOpenArray(0, 0)
block:
proc foo(x: openArray[int]) =
doAssert x[0] == 0
proc task(x: var array[1, int]): var array[1, int] =
result = x
var d: array[1, int]
foo task(d).toOpenArray(0, 0)
block:
proc foo(x: openArray[int]) =
doAssert x[0] == 0
proc task(x: var array[1, int]): lent array[1, int] =
result = x
var d: array[1, int]
foo task(d).toOpenArray(0, 0)
block:
proc foo(x: openArray[int]) =
doAssert x[0] == 0
proc task(x: var array[1, int]): ptr array[1, int] =
result = addr x
var d: array[1, int]
foo task(d)[].toOpenArray(0, 0)
main()
static: main()