Extend the fix for #11018 to strings (#11031)

* Extend the fix for #11018 to strings

* Fix testcase
This commit is contained in:
Clyybber 2019-04-15 17:06:31 +02:00 • committed by Andreas Rumpf
commit 2f56dd6b2b
2 changed files with 10 additions and 2 deletions

View file

@ -1839,7 +1839,7 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) =
if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes: if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes:
putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" % putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" %
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage) [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
elif p.config.selectedGc == gcDestructors and etyp.kind == tySequence: elif p.config.selectedGc == gcDestructors and etyp.kind in {tySequence, tyString}:
putIntoDest(p, d, e, "(*($1*) (&$2))" % putIntoDest(p, d, e, "(*($1*) (&$2))" %
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage) [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
else: else:

View file

@ -1,7 +1,9 @@
discard """ discard """
cmd: '''nim c --newruntime $file''' cmd: '''nim c --newruntime $file'''
output: '''@[1] output: '''@[1]
@[116, 101, 115, 116]''' @[116, 101, 115, 116]
test
@[1953719668, 875770417]'''
""" """
# bug #11018 # bug #11018
@ -9,3 +11,9 @@ discard cast[seq[uint8]](@[1])
discard cast[seq[uint8]]("test") discard cast[seq[uint8]]("test")
echo cast[seq[uint8]](@[1]) echo cast[seq[uint8]](@[1])
echo cast[seq[uint8]]("test") echo cast[seq[uint8]]("test")
discard cast[string](@[116'u8, 101, 115, 116])
echo cast[string](@[116'u8, 101, 115, 116])
var a = cast[seq[uint32]]("test1234")
a.setLen(2)
echo a