summary refs log tree commit diff stats
path: root/tests/ccgbugs/tobjconstr_bad_aliasing.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ccgbugs/tobjconstr_bad_aliasing.nim')
-rw-r--r--tests/ccgbugs/tobjconstr_bad_aliasing.nim56
1 files changed, 53 insertions, 3 deletions
diff --git a/tests/ccgbugs/tobjconstr_bad_aliasing.nim b/tests/ccgbugs/tobjconstr_bad_aliasing.nim
index ea51ecacb..550f9ab75 100644
--- a/tests/ccgbugs/tobjconstr_bad_aliasing.nim
+++ b/tests/ccgbugs/tobjconstr_bad_aliasing.nim
@@ -1,5 +1,9 @@
 discard """
-  output: '''(10, (20, ))'''
+  output: '''(10, (20, ))
+42
+(x: 900.0, y: 900.0)
+(x: 900.0, y: 900.0)
+(x: 900.0, y: 900.0)'''
 """
 
 import strutils, sequtils
@@ -22,5 +26,51 @@ proc dosomething(): seq[TThing] =
 
   result = @[TThing(data: 10, children: result)]
 
-when isMainModule:
-  echo($dosomething()[0])
+echo($dosomething()[0])
+
+
+# bug #9844
+
+proc f(v: int): int = v
+
+type X = object
+  v: int
+
+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))