tisopr.nim 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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)