tpush.nim 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. discard """
  2. targets: "c js"
  3. """
  4. # test the new pragmas
  5. {.push warnings: off, hints: off.}
  6. proc noWarning() =
  7. var
  8. x: int
  9. echo(x)
  10. {.pop.}
  11. proc WarnMe() =
  12. var
  13. x: int
  14. echo(x)
  15. # bug #11852
  16. proc foo(x: string, y: int, res: int) =
  17. {.push checks: off}
  18. var a: ptr char = unsafeAddr(x[y])
  19. {.pop.}
  20. if x.len > y:
  21. doAssert ord(a[]) == 51
  22. else:
  23. doAssert x.len + 48 == res
  24. foo("", 0, 48)
  25. foo("abc", 40, 51)
  26. # bug #22362
  27. {.push staticBoundChecks: on.}
  28. proc main(): void =
  29. {.pop.}
  30. discard
  31. {.push staticBoundChecks: on.}
  32. main()
  33. proc timnFoo[T](obj: T) {.noSideEffect.} = discard # BUG
  34. {.push exportc.}
  35. proc foo1() =
  36. var s1 = "bar"
  37. timnFoo(s1)
  38. var s2 = @[1]
  39. timnFoo(s2)
  40. {.pop.}
  41. block: # bug #22913
  42. block:
  43. type r = object
  44. template std[T](x: T) =
  45. let ttt {.used.} = x
  46. result = $ttt
  47. proc bar[T](x: T): string =
  48. std(x)
  49. {.push exportc: "$1".}
  50. proc foo(): r =
  51. let s = bar(123)
  52. {.pop.}
  53. discard foo()
  54. block:
  55. type r = object
  56. {.push exportc: "$1".}
  57. proc foo2(): r =
  58. let s = $result
  59. {.pop.}
  60. discard foo2()
  61. block: # bug #23019
  62. proc f(x: bool)
  63. proc a(x: int) =
  64. if false: f(true)
  65. proc f(x: bool) =
  66. if false: a(0)
  67. proc k(r: int|int) {.inline.} = # seems to require being generic and inline
  68. if false: a(0)
  69. # {.push tags: [].}
  70. {.push raises: [].}
  71. {.push warning[ObservableStores]:off.} # can be any warning, off or on
  72. let w = 0
  73. k(w)
  74. {.pop.}
  75. {.pop.}
  76. {.push exportC.}
  77. block:
  78. proc foo11() =
  79. const factor = [1, 2, 3, 4]
  80. doAssert factor[0] == 1
  81. proc foo21() =
  82. const factor = [1, 2, 3, 4]
  83. doAssert factor[0] == 1
  84. foo11()
  85. foo21()
  86. template foo31() =
  87. let factor = [1, 2, 3, 4]
  88. doAssert factor[0] == 1
  89. template foo41() =
  90. let factor = [1, 2, 3, 4]
  91. doAssert factor[0] == 1
  92. foo31()
  93. foo41()
  94. {.pop.}