mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 17:34:43 +00:00
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.
40 lines
551 B
Nim
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
|