taliasbugs.nim 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. discard """
  2. nimout: '''true
  3. true
  4. true
  5. true
  6. true
  7. true'''
  8. output: '''true
  9. true
  10. true
  11. true
  12. true
  13. true
  14. R
  15. R
  16. R
  17. R
  18. 19
  19. (c: 0)
  20. (c: 13)
  21. @[(c: 11)]
  22. @[(c: 17)]
  23. 100'''
  24. """
  25. # bug #5360
  26. import macros
  27. type
  28. Order = enum
  29. R
  30. OrderAlias = Order
  31. template getOrderTypeA(): typedesc = Order
  32. template getOrderTypeB(): typedesc = OrderAlias
  33. type
  34. OrderR = getOrderTypeA()
  35. OrderG = getOrderTypeB()
  36. macro typeRep(a, b: typed): untyped =
  37. if sameType(a, b):
  38. echo "true"
  39. else:
  40. echo "false"
  41. template test(a, b: typedesc) =
  42. when a is b:
  43. echo "true"
  44. else:
  45. echo "false"
  46. test(OrderAlias, Order)
  47. test(OrderR, Order)
  48. test(OrderG, Order)
  49. test(OrderR, OrderG)
  50. test(OrderR, OrderAlias)
  51. test(OrderG, OrderAlias)
  52. typeRep(OrderAlias.R, Order.R) # true
  53. typeRep(OrderR.R, Order.R) # true
  54. typeRep(OrderG.R, Order.R) # true
  55. typeRep(OrderR.R, OrderAlias.R) # true
  56. typeRep(OrderG.R, OrderAlias.R) # true
  57. typeRep(OrderR.R, OrderG.R) # true
  58. echo OrderR.R # R
  59. echo OrderG.R # R
  60. echo OrderAlias.R # R
  61. echo Order.R # R
  62. # bug #5238
  63. type
  64. Rgba8 = object
  65. c: int
  66. BlenderRgb*[ColorT] = object
  67. template getColorType*[C](x: typedesc[BlenderRgb[C]]): typedesc = C
  68. type
  69. ColorT = getColorType(BlenderRgb[int])
  70. proc setColor(c: var ColorT) =
  71. c = 19
  72. var n: ColorT
  73. n.setColor()
  74. echo n
  75. type
  76. ColorType = getColorType(BlenderRgb[Rgba8])
  77. var x: ColorType
  78. echo x
  79. proc setColor(c: var ColorType) =
  80. c = Rgba8(c: 13)
  81. proc setColor(c: var seq[ColorType]) =
  82. c[0] = Rgba8(c: 11)
  83. proc setColorArray(c: var openArray[ColorType]) =
  84. c[0] = Rgba8(c: 17)
  85. x.setColor()
  86. echo x
  87. var y = @[Rgba8(c:15)]
  88. y.setColor()
  89. echo y
  90. y.setColorArray()
  91. echo y
  92. #bug #6016
  93. type
  94. Onion {.union.} = object
  95. field1: int
  96. field2: uint64
  97. Stroom = Onion
  98. PStroom = ptr Stroom
  99. proc pstruct(u: PStroom) =
  100. echo u.field2
  101. var oni = Onion(field1: 100)
  102. pstruct(oni.addr)
  103. # bug #4124
  104. import sequtils
  105. type
  106. Foo = distinct string
  107. var
  108. foo: Foo
  109. type
  110. Alias = (type(foo))
  111. var
  112. a: Alias
  113. a = foo
  114. when true:
  115. var xs = @[1,2,3]
  116. proc asFoo(i: string): Foo =
  117. Foo(i)
  118. var xx = xs.mapIt(asFoo($(it + 5)))
  119. block t4674:
  120. type
  121. FooObj[T] = object
  122. v: T
  123. Foo1[T] = FooObj[T]
  124. Foo2 = FooObj
  125. Foo1x = Foo1
  126. Foo12x = Foo1 | Foo2
  127. Foo2x = Foo2 # Error: illegal recursion in type 'Foo2x'