diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 10b17663e6825..632e4bb31cc6d 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2974,7 +2974,7 @@ proc genBracedInit(p: BProc, n: PNode; isConst: bool): Rope = of tyObject: result = genConstObjConstr(p, n, isConst) of tyString, tyCString: - if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit: + if optSeqDestructors in p.config.globalOptions and n.kind != nkNilLit and ty == tyString: result = genStringLiteralV2Const(p.module, n, isConst) else: var d: TLoc diff --git a/tests/arc/tcstring.nim b/tests/arc/tcstring.nim new file mode 100644 index 0000000000000..79c8a7fcf0317 --- /dev/null +++ b/tests/arc/tcstring.nim @@ -0,0 +1,16 @@ +discard """ + cmd: "nim c --gc:arc -r $file" + nimout: '''hello +h +o +''' +""" + +# Issue #13321: [codegen] --gc:arc does not properly emit cstring, results in SIGSEGV + +let a = "hello".cstring +echo a +echo a[0] +echo a[4] +doAssert a[a.len] == '\0' +