Skip to content

Commit cd22560

Browse files
authored
fix string literal assignment with different lengths on ARC (#24083)
fixes #24080
1 parent 7cd1777 commit cd22560

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/system/strs_v2.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ proc setLengthStrV2(s: var NimStringV2, newLen: int) {.compilerRtl.} =
166166
s.len = newLen
167167

168168
proc nimAsgnStrV2(a: var NimStringV2, b: NimStringV2) {.compilerRtl.} =
169-
if a.p == b.p: return
169+
if a.p == b.p and a.len == b.len: return
170170
if isLiteral(b):
171171
# we can shallow copy literals:
172172
frees(a)

tests/arc/tstringliteral.nim

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
discard """
2+
matrix: "--mm:arc; --mm:orc"
3+
"""
4+
5+
block: # issue #24080
6+
var a = (s: "a")
7+
var b = "a"
8+
a.s.setLen 0
9+
b = a.s
10+
doAssert b == ""
11+
12+
block: # issue #24080, longer string
13+
var a = (s: "abc")
14+
var b = "abc"
15+
a.s.setLen 2
16+
b = a.s
17+
doAssert b == "ab"

0 commit comments

Comments
 (0)