diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-04-03 22:59:35 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-03 16:59:35 +0200 |
commit | 9e1b170a09d2228214807a8c01fe37b874f77d58 (patch) | |
tree | 72acf23b56a05eabfd21e52f740e2b4505eb3f8b /tests/stdlib | |
parent | dee55f587f4e3cfc8ffe28e4a41eba9c8ed7f2f8 (diff) | |
download | Nim-9e1b170a09d2228214807a8c01fe37b874f77d58.tar.gz |
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.
Diffstat (limited to 'tests/stdlib')
-rw-r--r-- | tests/stdlib/tmisc_issues.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/stdlib/tmisc_issues.nim b/tests/stdlib/tmisc_issues.nim index 33eb9655d..86dcf4162 100644 --- a/tests/stdlib/tmisc_issues.nim +++ b/tests/stdlib/tmisc_issues.nim @@ -18,3 +18,22 @@ type 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 |