tissues_types.nim 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. discard """
  2. output: '''true
  3. true
  4. true
  5. true
  6. ptr Foo
  7. (member: "hello world")
  8. (member: 123.456)
  9. (member: "hello world", x: ...)
  10. (member: 123.456, x: ...)
  11. 0
  12. false
  13. '''
  14. joinable: false
  15. """
  16. # not joinable because it causes out of memory with --gc:boehm
  17. import typetraits
  18. block t1252:
  19. echo float32 isnot float64
  20. echo float32 isnot float
  21. echo int32 isnot int64
  22. echo int32 isnot int
  23. block t5640:
  24. type
  25. vecBase[I: static[int]] = distinct array[I, float32]
  26. vec2 = vecBase[2]
  27. var v = vec2([0.0'f32, 0.0'f32])
  28. block t5648:
  29. type Foo = object
  30. bar: int
  31. proc main() =
  32. var f = create(Foo)
  33. f.bar = 3
  34. echo f.type.name
  35. discard realloc(f, 0)
  36. var g = Foo()
  37. g.bar = 3
  38. var
  39. mainPtr1: pointer = main
  40. mainPtr2 = pointer(main)
  41. mainPtr3 = cast[pointer](main)
  42. doAssert mainPtr1 == mainPtr2 and mainPtr2 == mainPtr3
  43. main()
  44. block t7581:
  45. discard int -1
  46. block t7905:
  47. template foobar(arg: typed): untyped =
  48. type
  49. MyType = object
  50. member: type(arg)
  51. var myVar: MyType
  52. myVar.member = arg
  53. echo myVar
  54. foobar("hello world")
  55. foobar(123.456'f64)
  56. template foobarRec(arg: typed): untyped =
  57. type
  58. MyType = object
  59. member: type(arg)
  60. x: ref MyType
  61. var myVar: MyType
  62. myVar.member = arg
  63. echo myVar
  64. foobarRec("hello world")
  65. foobarRec(123.456'f64)
  66. # bug #5170
  67. when true:
  68. type Foo = object
  69. bar: bool
  70. type Bar = object
  71. sameBody: string
  72. var b0: Bar
  73. b0.sameBody = "abc"
  74. block:
  75. type Foo = object
  76. baz: int
  77. type Bar = object
  78. sameBody: string
  79. var b1: Bar
  80. b1.sameBody = "def"
  81. var f2: Foo
  82. echo f2.baz
  83. var f1: Foo
  84. echo f1.bar