mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
fix string literal assignment with different lengths on ARC (#24083)
fixes #24080
This commit is contained in:
@@ -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)
|
||||
|
||||
17
tests/arc/tstringliteral.nim
Normal file
17
tests/arc/tstringliteral.nim
Normal 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"
|
||||
Reference in New Issue
Block a user