fix string literal assignment with different lengths on ARC (#24083)

fixes #24080
This commit is contained in:
metagn
2024-09-08 21:17:26 +03:00
committed by GitHub
parent 7cd1777218
commit cd22560af5
2 changed files with 18 additions and 1 deletions

View File

@@ -166,7 +166,7 @@ proc setLengthStrV2(s: var NimStringV2, newLen: int) {.compilerRtl.} =
s.len = newLen
proc nimAsgnStrV2(a: var NimStringV2, b: NimStringV2) {.compilerRtl.} =
if a.p == b.p: return
if a.p == b.p and a.len == b.len: return
if isLiteral(b):
# we can shallow copy literals:
frees(a)

View File

@@ -0,0 +1,17 @@
discard """
matrix: "--mm:arc; --mm:orc"
"""
block: # issue #24080
var a = (s: "a")
var b = "a"
a.s.setLen 0
b = a.s
doAssert b == ""
block: # issue #24080, longer string
var a = (s: "abc")
var b = "abc"
a.s.setLen 2
b = a.s
doAssert b == "ab"