Skip to content

Commit

Permalink
fix string literal assignment with different lengths on ARC (#24083)
Browse files Browse the repository at this point in the history
fixes #24080
  • Loading branch information
metagn authored Sep 8, 2024
1 parent 7cd1777 commit cd22560
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/system/strs_v2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/arc/tstringliteral.nim
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit cd22560

Please sign in to comment.