summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ccgbugs/tobjconstr_bad_aliasing.nim26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/ccgbugs/tobjconstr_bad_aliasing.nim b/tests/ccgbugs/tobjconstr_bad_aliasing.nim
new file mode 100644
index 000000000..ea51ecacb
--- /dev/null
+++ b/tests/ccgbugs/tobjconstr_bad_aliasing.nim
@@ -0,0 +1,26 @@
+discard """
+  output: '''(10, (20, ))'''
+"""
+
+import strutils, sequtils
+
+# bug #668
+
+type
+  TThing = ref object
+    data: int
+    children: seq[TThing]
+
+proc `$`(t: TThing): string =
+  result = "($1, $2)" % @[$t.data, join(map(t.children, proc(th: TThing): string = $th), ", ")]
+
+proc somethingelse(): seq[TThing] =
+  result = @[TThing(data: 20, children: @[])]
+
+proc dosomething(): seq[TThing] =
+  result = somethingelse()
+
+  result = @[TThing(data: 10, children: result)]
+
+when isMainModule:
+  echo($dosomething()[0])