From 499fa3f3dc822eb0895116db84e3c63746d4e1a2 Mon Sep 17 00:00:00 2001 From: Clyybber Date: Sun, 14 Apr 2019 23:34:19 +0200 Subject: [PATCH] Fixes #11018 (#11019) --- compiler/ccgexprs.nim | 3 +++ tests/destructor/tv2_cast.nim | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 tests/destructor/tv2_cast.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index cc054b33a2..58a45f1f53 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1839,6 +1839,9 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) = if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes: putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" % [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage) + elif p.config.selectedGc == gcDestructors and etyp.kind == tySequence: + putIntoDest(p, d, e, "(*($1*) (&$2))" % + [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage) else: putIntoDest(p, d, e, "(($1) ($2))" % [getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage) diff --git a/tests/destructor/tv2_cast.nim b/tests/destructor/tv2_cast.nim new file mode 100644 index 0000000000..1430b75218 --- /dev/null +++ b/tests/destructor/tv2_cast.nim @@ -0,0 +1,11 @@ +discard """ + cmd: '''nim c --newruntime $file''' + output: '''@[1] +@[116, 101, 115, 116]''' +""" + +# bug #11018 +discard cast[seq[uint8]](@[1]) +discard cast[seq[uint8]]("test") +echo cast[seq[uint8]](@[1]) +echo cast[seq[uint8]]("test")