diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2023-06-16 20:59:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-16 20:59:59 +0200 |
commit | e8d0f1c3aedd8290cc972e3d06f642e88dbe783e (patch) | |
tree | fff0c7880eb78749439c3c57fae764978405531d /tests/ccgbugs/twrong_tupleconv.nim | |
parent | 0de9e6bbf33bd013e39025f0ee81fc86956e70cf (diff) | |
download | Nim-e8d0f1c3aedd8290cc972e3d06f642e88dbe783e.tar.gz |
fixes #16331; aliasing of tuple construction within a single assignme… (#22113)
* fixes #16331; aliasing of tuple construction within a single assignment, great coding style * added test case
Diffstat (limited to 'tests/ccgbugs/twrong_tupleconv.nim')
-rw-r--r-- | tests/ccgbugs/twrong_tupleconv.nim | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/ccgbugs/twrong_tupleconv.nim b/tests/ccgbugs/twrong_tupleconv.nim index 7a887d183..031712dac 100644 --- a/tests/ccgbugs/twrong_tupleconv.nim +++ b/tests/ccgbugs/twrong_tupleconv.nim @@ -1,3 +1,8 @@ +discard """ + targets: "c cpp" + matrix: "--gc:refc; --gc:arc" +""" + # bug #1833 iterator myitems*[T](a: var seq[T]): var T {.inline.} = ## iterates over each item of `a` so that you can modify the yielded value. @@ -18,3 +23,13 @@ var ys = @[(1,"a"),(2,"b"),(3,"c")] for y in myitems(ys): inc y[0] +# bug #16331 +type T1 = tuple[a, b: int] + +proc p(b: bool): string = + var x: T1 = (10, 20) + x = if b: (x.b, x.a) else: (-x.b, -x.a) + $x + +assert p(false) == "(a: -20, b: -10)" +assert p(true) == "(a: 20, b: 10)" |