tissues_types.nim 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. discard """
  2. output: '''true
  3. true
  4. true
  5. true
  6. (member: "hello world")
  7. (member: 123.456)
  8. (member: "hello world", x: ...)
  9. (member: 123.456, x: ...)
  10. 0
  11. false
  12. '''
  13. """
  14. block t1252:
  15. echo float32 isnot float64
  16. echo float32 isnot float
  17. echo int32 isnot int64
  18. echo int32 isnot int
  19. block t5640:
  20. type
  21. vecBase[I: static[int]] = distinct array[I, float32]
  22. vec2 = vecBase[2]
  23. var v = vec2([0.0'f32, 0.0'f32])
  24. block t7581:
  25. discard int -1
  26. block t7905:
  27. template foobar(arg: typed): untyped =
  28. type
  29. MyType = object
  30. member: type(arg)
  31. var myVar: MyType
  32. myVar.member = arg
  33. echo myVar
  34. foobar("hello world")
  35. foobar(123.456'f64)
  36. template foobarRec(arg: typed): untyped =
  37. type
  38. MyType = object
  39. member: type(arg)
  40. x: ref MyType
  41. var myVar: MyType
  42. myVar.member = arg
  43. echo myVar
  44. foobarRec("hello world")
  45. foobarRec(123.456'f64)
  46. # bug #5170
  47. when true:
  48. type Foo = object
  49. bar: bool
  50. type Bar = object
  51. sameBody: string
  52. var b0: Bar
  53. b0.sameBody = "abc"
  54. block:
  55. type Foo = object
  56. baz: int
  57. type Bar = object
  58. sameBody: string
  59. var b1: Bar
  60. b1.sameBody = "def"
  61. var f2: Foo
  62. echo f2.baz
  63. var f1: Foo
  64. echo f1.bar
  65. import macros
  66. block: # issue #12582
  67. macro foo(T: type): type =
  68. nnkBracketExpr.newTree(bindSym "array", newLit 1, T)
  69. var
  70. _: foo(int) # fine
  71. type
  72. Foo = object
  73. x: foo(int) # fine
  74. Bar = ref object
  75. x: foo(int) # error
  76. let b = Bar()
  77. let b2 = Bar(x: [123])
  78. block:
  79. when true: # bug #14710
  80. type Foo[T] = object
  81. x1: int
  82. when T.sizeof == 4: discard # SIGSEGV
  83. when sizeof(T) == 4: discard # ok
  84. let t = Foo[float](x1: 1)
  85. doAssert t.x1 == 1
  86. block:
  87. template s(d: varargs[typed])=discard
  88. proc something(x:float)=discard
  89. proc something(x:int)=discard
  90. proc otherthing()=discard
  91. s(something)
  92. s(otherthing, something)
  93. s(something, otherthing)