tsamename3.nim 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. block: # bug #15526
  2. block:
  3. type Foo = ref object
  4. x1: int
  5. let f1 = Foo(x1: 1)
  6. block:
  7. type Foo = ref object
  8. x2: int
  9. let f2 = Foo(x2: 2)
  10. block: # ditto
  11. template fn() =
  12. block:
  13. type Foo = ref object
  14. x1: int
  15. let f1 = Foo(x1: 1)
  16. doAssert f1.x1 == 1
  17. block:
  18. type Foo = ref object
  19. x2: int
  20. let f2 = Foo(x2: 2)
  21. doAssert f2.x2 == 2
  22. static: fn()
  23. fn()
  24. block: # bug #17162
  25. template fn =
  26. var ret: string
  27. block:
  28. type A = enum a0, a1, a2
  29. for ai in A:
  30. ret.add $ai
  31. block:
  32. type A = enum b0, b1, b2, b3
  33. for ai in A:
  34. ret.add $ai
  35. doAssert ret == "a0a1a2b0b1b2b3"
  36. static: fn() # ok
  37. fn() # was bug
  38. block: # ditto
  39. proc fn =
  40. var ret: string
  41. block:
  42. type A = enum a0, a1, a2
  43. for ai in A:
  44. ret.add $ai
  45. block:
  46. type A = enum b0, b1, b2, b3
  47. for ai in A:
  48. ret.add $ai
  49. doAssert ret == "a0a1a2b0b1b2b3"
  50. static: fn() # ok
  51. fn() # was bug
  52. block: # bug #5170
  53. block:
  54. type Foo = object
  55. x1: int
  56. let f1 = Foo(x1: 1)
  57. block:
  58. type Foo = object
  59. x2: int
  60. let f2 = Foo(x2: 2)
  61. block: # ditto
  62. block:
  63. type Foo = object
  64. bar: bool
  65. var f1: Foo
  66. block:
  67. type Foo = object
  68. baz: int
  69. var f2: Foo
  70. doAssert f2.baz == 0
  71. block:
  72. template fn() =
  73. block:
  74. type Foo = object
  75. x1: int
  76. let f1 = Foo(x1: 1)
  77. doAssert f1.x1 == 1
  78. block:
  79. type Foo = object
  80. x2: int
  81. let f2 = Foo(x2: 2)
  82. doAssert f2.x2 == 2
  83. static: fn()
  84. fn()
  85. when true: # ditto, refs https://github.com/nim-lang/Nim/issues/5170#issuecomment-582712132
  86. type Foo1 = object # at top level
  87. bar: bool
  88. var f1: Foo1
  89. block:
  90. type Foo1 = object
  91. baz: int
  92. var f2: Foo1
  93. doAssert f2.baz == 0
  94. block: # make sure `hashType` doesn't recurse infinitely
  95. type
  96. PFoo = ref object
  97. a, b: PFoo
  98. c: int
  99. var a: PFoo