Files
Nim/tests/stdlib/tmisc_issues.nim
ringabout 9e1b170a09 fixes #16771; lower swap for JS backend (#23473)
fixes #16771

follow up https://github.com/nim-lang/Nim/pull/16536

Ideally it should be handled in the IR part in the future

I have also checked the double evaluation of `swap` in the JS runtime
https://github.com/nim-lang/Nim/issues/16779, that might be solved by a
copy flag or something. Well, it should be best solved in the IR so that
it doesn't bother backends anymore.
2024-04-03 16:59:35 +02:00

40 lines
551 B
Nim

discard """
matrix: "--mm:refc; --mm:orc"
targets: "c cpp js"
"""
import std/assertions
# bug #20227
type
Data = object
id: int
Test = distinct Data
Object = object
data: Test
var x: Object = Object(data: Test(Data(id: 12)))
doAssert Data(x.data).id == 12
block: # bug #16771
type A = object
n: int
proc foo(a, b: var A) =
swap a, b
var a, b: A
a.n = 42
b.n = 1
doAssert a.n == 42
doAssert b.n == 1
a.swap b
doAssert a.n == 1
doAssert b.n == 42
a.foo b
doAssert a.n == 42
doAssert b.n == 1