tisopr.nim 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. discard """
  2. output: '''true true false yes
  3. false
  4. true
  5. false
  6. true
  7. true
  8. yes'''
  9. """
  10. proc IsVoid[T](): string =
  11. when T is void:
  12. result = "yes"
  13. else:
  14. result = "no"
  15. const x = int is int
  16. echo x, " ", float is float, " ", float is string, " ", IsVoid[void]()
  17. template yes(e): void =
  18. static: assert e
  19. template no(e): void =
  20. static: assert(not e)
  21. when false:
  22. var s = @[1, 2, 3]
  23. yes s.items is iterator
  24. no s.items is proc
  25. yes s.items is iterator: int
  26. no s.items is iterator: float
  27. yes s.items is iterator: TNumber
  28. no s.items is iterator: object
  29. type
  30. Iter[T] = iterator: T
  31. yes s.items is Iter[TNumber]
  32. no s.items is Iter[float]
  33. type
  34. Foo[N: static[int], T] = object
  35. field: array[1..N, T]
  36. Bar[T] = Foo[4, T]
  37. Baz[N: static[int]] = Foo[N, float]
  38. no Foo[2, float] is Foo[3, float]
  39. no Foo[2, float] is Foo[2, int]
  40. yes Foo[4, string] is Foo[4, string]
  41. yes Bar[int] is Foo[4, int]
  42. yes Foo[4, int] is Bar[int]
  43. no Foo[4, int] is Baz[4]
  44. yes Foo[4, float] is Baz[4]
  45. # bug #2505
  46. echo(8'i8 is int32)
  47. # bug #1853
  48. type SeqOrSet[E] = seq[E] or set[E]
  49. type SeqOfInt = seq[int]
  50. type SeqOrSetOfInt = SeqOrSet[int]
  51. # This prints "true", as expected. Previously "false" was returned and that
  52. # seemed less correct that (1) printing "true" or (2) raising a compiler error.
  53. echo seq is SeqOrSet
  54. # This prints "false", as expected.
  55. echo seq is SeqOrSetOfInt
  56. # This prints "true", as expected.
  57. echo SeqOfInt is SeqOrSet
  58. # This causes an internal error (filename: compiler/semtypes.nim, line: 685).
  59. echo SeqOfInt is SeqOrSetOfInt
  60. # bug #2522
  61. proc test[T](x: T) =
  62. when T is typedesc:
  63. echo "yes"
  64. else:
  65. echo "no"
  66. test(7)
  67. block:
  68. # bug #13066
  69. type Bar[T1,T2] = object
  70. type Foo[T1,T2] = object
  71. type Foo2 = Foo
  72. doAssert Foo2 is Foo
  73. doAssert Foo is Foo2
  74. doAssert Foo is Foo
  75. doAssert Foo2 is Foo2
  76. doAssert Foo2 isnot Bar
  77. doAssert Foo[int,float] is Foo2[int,float]
  78. # other
  79. doAssert Foo[int,float] isnot Foo2[float,float]
  80. doAssert Foo[int,float] is Foo2
  81. doAssert Foo[int,float|int] is Foo2
  82. doAssert Foo2[int,float|int] is Foo
  83. doAssert Foo2[int,float|int] isnot Bar
  84. doAssert int is (int|float)