mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user