t4668.nim 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. discard """
  2. output: '''
  3. foo1
  4. foo2
  5. '''
  6. """
  7. block:
  8. type
  9. FooObj[T] = object
  10. v: T
  11. Foo1[T] = FooObj[T]
  12. Foo2 = FooObj
  13. proc foo1(x: Foo1) = echo "foo1"
  14. proc foo2(x: Foo2) = echo "foo2"
  15. var x: FooObj[float]
  16. foo1(x) # works
  17. foo2(x) # works
  18. block:
  19. type
  20. FooObj[T] = T
  21. Foo1[T] = FooObj[T]
  22. Foo2 = FooObj
  23. Foo3 = Foo1
  24. Foo4x = FooObj[SomeInteger]
  25. Foo4 = FooObj[SomeFloat]
  26. Foo5x = Foo1[SomeInteger]
  27. Foo5 = Foo1[SomeFloat]
  28. proc foo0(x: FooObj): int = 0
  29. proc foo1(x: Foo1): int = 1
  30. proc foo2(x: Foo2): int = 2
  31. proc foo3(x: Foo3): int = 3
  32. proc foo4(x: Foo4x): int = 40
  33. proc foo4(x: Foo4): int = 4
  34. proc foo5(x: Foo5x): int = 50
  35. proc foo5(x: Foo5): int = 5
  36. block:
  37. var x: FooObj[float]
  38. doAssert(foo0(x) == 0)
  39. doAssert(foo1(x) == 1)
  40. doAssert(foo2(x) == 2)
  41. doAssert(foo3(x) == 3)
  42. doAssert(foo4(x) == 4)
  43. doAssert(foo5(x) == 5)
  44. block:
  45. var x: Foo1[float]
  46. doAssert(foo0(x) == 0)
  47. doAssert(foo1(x) == 1)
  48. doAssert(foo2(x) == 2)
  49. doAssert(foo3(x) == 3)
  50. doAssert(foo4(x) == 4)
  51. doAssert(foo5(x) == 5)
  52. block:
  53. var x: Foo2[float]
  54. doAssert(foo0(x) == 0)
  55. doAssert(foo1(x) == 1)
  56. doAssert(foo2(x) == 2)
  57. doAssert(foo3(x) == 3)
  58. doAssert(foo4(x) == 4)
  59. doAssert(foo5(x) == 5)
  60. block:
  61. type
  62. FooObj[T,U] = object
  63. x: T
  64. y: U
  65. Foo1[U,T] = FooObj[T,U]
  66. Foo2 = FooObj
  67. Foo3 = Foo1
  68. Foo4x = FooObj[SomeInteger,SomeInteger]
  69. Foo4y = FooObj[SomeInteger,SomeFloat]
  70. Foo4z = FooObj[SomeFloat,SomeFloat]
  71. Foo4 = FooObj[SomeFloat,SomeInteger]
  72. Foo5x = Foo1[SomeInteger,SomeInteger]
  73. Foo5y = Foo1[SomeFloat,SomeInteger]
  74. Foo5z = Foo1[SomeFloat,SomeFloat]
  75. Foo5 = Foo1[SomeInteger,SomeFloat]
  76. proc foo0(x: FooObj): int = 0
  77. proc foo1(x: Foo1): int = 1
  78. proc foo2(x: Foo2): int = 2
  79. proc foo3(x: Foo3): int = 3
  80. proc foo4(x: Foo4x): int = 40
  81. proc foo4(x: Foo4y): int = 41
  82. proc foo4(x: Foo4z): int = 42
  83. proc foo4(x: Foo4): int = 4
  84. proc foo5(x: Foo5x): int = 50
  85. proc foo5(x: Foo5y): int = 51
  86. proc foo5(x: Foo5z): int = 52
  87. proc foo5(x: Foo5): int = 5
  88. block:
  89. var x: FooObj[float,int]
  90. doAssert(foo0(x) == 0)
  91. doAssert(foo1(x) == 1)
  92. doAssert(foo2(x) == 2)
  93. doAssert(foo3(x) == 3)
  94. doAssert(foo4(x) == 4)
  95. doAssert(foo5(x) == 5)
  96. block:
  97. var x: Foo1[int,float]
  98. doAssert(foo0(x) == 0)
  99. doAssert(foo1(x) == 1)
  100. doAssert(foo2(x) == 2)
  101. doAssert(foo3(x) == 3)
  102. doAssert(foo4(x) == 4)
  103. doAssert(foo5(x) == 5)
  104. block:
  105. type
  106. FooObj[T] = object of RootObj
  107. v: T
  108. FooObj2[T] = object of FooObj[T]
  109. Foo1[T] = FooObj[T]
  110. Foo2 = FooObj
  111. Foo3 = Foo1
  112. Foo4x = FooObj[SomeInteger]
  113. Foo4 = FooObj[SomeFloat]
  114. Foo5x = Foo1[SomeInteger]
  115. Foo5 = Foo1[SomeFloat]
  116. proc foo0(x: FooObj): int = 0
  117. proc foo1(x: Foo1): int = 1
  118. proc foo2(x: Foo2): int = 2
  119. proc foo3(x: Foo3): int = 3
  120. proc foo4(x: Foo4x): int = 40
  121. proc foo4(x: Foo4): int = 4
  122. proc foo5(x: Foo5x): int = 50
  123. proc foo5(x: Foo5): int = 5
  124. block:
  125. var x: FooObj[float]
  126. doAssert(foo0(x) == 0)
  127. doAssert(foo1(x) == 1)
  128. doAssert(foo2(x) == 2)
  129. doAssert(foo3(x) == 3)
  130. doAssert(foo4(x) == 4)
  131. doAssert(foo5(x) == 5)
  132. block:
  133. var x: Foo1[float]
  134. doAssert(foo0(x) == 0)
  135. doAssert(foo1(x) == 1)
  136. doAssert(foo2(x) == 2)
  137. doAssert(foo3(x) == 3)
  138. doAssert(foo4(x) == 4)
  139. doAssert(foo5(x) == 5)
  140. #[ XXX These still fail
  141. block:
  142. var x: FooObj2[float]
  143. doAssert(foo0(x) == 0)
  144. doAssert(foo1(x) == 1)
  145. doAssert(foo2(x) == 2)
  146. doAssert(foo3(x) == 3)
  147. doAssert(foo4(x) == 4)
  148. doAssert(foo5(x) == 5)
  149. ]#