diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-06-26 23:15:44 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-06-26 23:15:58 +0200 |
commit | 19b142401c9c7eece2cab7539ef626dc52a156fd (patch) | |
tree | 512aadb476b90b23eaffa1e189634a15b2cd11c4 /tests/ccgbugs/tobjconstr_bad_aliasing.nim | |
parent | 48cbf1c4960848dac9b2f63e17c57a837a234163 (diff) | |
download | Nim-19b142401c9c7eece2cab7539ef626dc52a156fd.tar.gz |
fixes #11525
Diffstat (limited to 'tests/ccgbugs/tobjconstr_bad_aliasing.nim')
-rw-r--r-- | tests/ccgbugs/tobjconstr_bad_aliasing.nim | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/tests/ccgbugs/tobjconstr_bad_aliasing.nim b/tests/ccgbugs/tobjconstr_bad_aliasing.nim index 2ac504903..550f9ab75 100644 --- a/tests/ccgbugs/tobjconstr_bad_aliasing.nim +++ b/tests/ccgbugs/tobjconstr_bad_aliasing.nim @@ -1,6 +1,9 @@ discard """ output: '''(10, (20, )) -42''' +42 +(x: 900.0, y: 900.0) +(x: 900.0, y: 900.0) +(x: 900.0, y: 900.0)''' """ import strutils, sequtils @@ -37,3 +40,37 @@ var x = X(v: 42) x = X(v: f(x.v)) echo x.v + + +# bug #11525 +type + Point[T] = object + x, y: T + +proc adjustPos[T](width, height: int, pos: Point[T]): Point[T] = + result = pos + + result = Point[T]( + x: pos.x - (width / 2), + y: pos.y - (height / 2) + ) + +proc adjustPos2[T](width, height: int, pos: Point[T]): Point[T] = + result = pos + + result = Point[T]( + x: result.x - (width / 2), + y: result.y - (height / 2) + ) + +proc adjustPos3(width, height: int, pos: Point): Point = + result = pos + + result = Point( + x: result.x - (width / 2), + y: result.y - (height / 2) + ) + +echo adjustPos(200, 200, Point[float](x: 1000, y: 1000)) +echo adjustPos2(200, 200, Point[float](x: 1000, y: 1000)) +echo adjustPos3(200, 200, Point[float](x: 1000, y: 1000)) |