tobjconstr_bad_aliasing.nim 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. discard """
  2. output: '''(10, (20, ))
  3. 42
  4. (x: 900.0, y: 900.0)
  5. (x: 900.0, y: 900.0)
  6. (x: 900.0, y: 900.0)'''
  7. """
  8. import strutils, sequtils
  9. # bug #668
  10. type
  11. TThing = ref object
  12. data: int
  13. children: seq[TThing]
  14. proc `$`(t: TThing): string =
  15. result = "($1, $2)" % @[$t.data, join(map(t.children, proc(th: TThing): string = $th), ", ")]
  16. proc somethingelse(): seq[TThing] =
  17. result = @[TThing(data: 20, children: @[])]
  18. proc dosomething(): seq[TThing] =
  19. result = somethingelse()
  20. result = @[TThing(data: 10, children: result)]
  21. echo($dosomething()[0])
  22. # bug #9844
  23. proc f(v: int): int = v
  24. type X = object
  25. v: int
  26. var x = X(v: 42)
  27. x = X(v: f(x.v))
  28. echo x.v
  29. # bug #11525
  30. type
  31. Point[T] = object
  32. x, y: T
  33. proc adjustPos[T](width, height: int, pos: Point[T]): Point[T] =
  34. result = pos
  35. result = Point[T](
  36. x: pos.x - (width / 2),
  37. y: pos.y - (height / 2)
  38. )
  39. proc adjustPos2[T](width, height: int, pos: Point[T]): Point[T] =
  40. result = pos
  41. result = Point[T](
  42. x: result.x - (width / 2),
  43. y: result.y - (height / 2)
  44. )
  45. proc adjustPos3(width, height: int, pos: Point): Point =
  46. result = pos
  47. result = Point(
  48. x: result.x - (width / 2),
  49. y: result.y - (height / 2)
  50. )
  51. echo adjustPos(200, 200, Point[float](x: 1000, y: 1000))
  52. echo adjustPos2(200, 200, Point[float](x: 1000, y: 1000))
  53. echo adjustPos3(200, 200, Point[float](x: 1000, y: 1000))