tconv.nim 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. discard """
  2. matrix: "--warningAsError:EnumConv --warningAsError:CStringConv"
  3. """
  4. template reject(x) =
  5. static: doAssert(not compiles(x))
  6. template accept(x) =
  7. static: doAssert(compiles(x))
  8. reject:
  9. const x = int8(300)
  10. reject:
  11. const x = int64(NaN)
  12. type
  13. R = range[0..10]
  14. reject:
  15. const x = R(11)
  16. reject:
  17. const x = R(11.0)
  18. reject:
  19. const x = R(NaN)
  20. reject:
  21. const x = R(Inf)
  22. type
  23. FloatRange = range[0'f..10'f]
  24. reject:
  25. const x = FloatRange(-1'f)
  26. reject:
  27. const x = FloatRange(-1)
  28. reject:
  29. const x = FloatRange(NaN)
  30. block:
  31. const x = float32(NaN)
  32. type E = enum a, b, c
  33. reject:
  34. const e = E(4)
  35. block: # issue 3766
  36. type R = range[0..2]
  37. reject:
  38. type
  39. T[n: static[R]] = object
  40. V = T[3.R]
  41. reject:
  42. proc r(x: static[R]) =
  43. echo x
  44. r 3.R
  45. block: # https://github.com/nim-lang/RFCs/issues/294
  46. type Koo = enum k1, k2
  47. type Goo = enum g1, g2
  48. accept: Koo(k2)
  49. accept: k2.Koo
  50. accept: k2.int.Goo
  51. reject: Goo(k2)
  52. reject: k2.Goo
  53. reject: k2.string
  54. {.push warningAsError[EnumConv]:off.}
  55. discard Goo(k2)
  56. accept: Goo(k2)
  57. accept: k2.Goo
  58. reject: k2.string
  59. {.pop.}
  60. reject: Goo(k2)
  61. reject: k2.Goo
  62. reject:
  63. # bug #18550
  64. proc f(c: char): cstring =
  65. var x = newString(109*1024*1024)
  66. x[0] = c
  67. x
  68. {.push warning[AnyEnumConv]:on, warningAsError[AnyEnumConv]:on.}
  69. reject:
  70. type
  71. Foo = enum
  72. one
  73. three
  74. var va = 2
  75. var vb = va.Foo
  76. {.pop.}
  77. {.push warningAsError[HoleEnumConv]:on.}
  78. reject:
  79. # bug #12815
  80. type
  81. Hole = enum
  82. one = 1
  83. three = 3
  84. var va = 2
  85. var vb = va.Hole
  86. {.pop.}