tobjconstr_bad_aliasing.nim 499 B

1234567891011121314151617181920212223242526
  1. discard """
  2. output: '''(10, (20, ))'''
  3. """
  4. import strutils, sequtils
  5. # bug #668
  6. type
  7. TThing = ref object
  8. data: int
  9. children: seq[TThing]
  10. proc `$`(t: TThing): string =
  11. result = "($1, $2)" % @[$t.data, join(map(t.children, proc(th: TThing): string = $th), ", ")]
  12. proc somethingelse(): seq[TThing] =
  13. result = @[TThing(data: 20, children: @[])]
  14. proc dosomething(): seq[TThing] =
  15. result = somethingelse()
  16. result = @[TThing(data: 10, children: result)]
  17. echo($dosomething()[0])