tvmmisc.nim 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # bug #4462
  2. import macros
  3. block:
  4. proc foo(t: typedesc) {.compileTime.} =
  5. assert sameType(getType(t), getType(int))
  6. static:
  7. foo(int)
  8. # #4412
  9. block:
  10. proc default[T](t: typedesc[T]): T {.inline.} = discard
  11. static:
  12. var x = default(type(0))
  13. # #6379
  14. static:
  15. import algorithm
  16. var numArray = [1, 2, 3, 4, -1]
  17. numArray.sort(cmp)
  18. assert numArray == [-1, 1, 2, 3, 4]
  19. var str = "cba"
  20. str.sort(cmp)
  21. assert str == "abc"
  22. # #6086
  23. import math, sequtils, future
  24. block:
  25. proc f: int =
  26. toSeq(10..<10_000).filter(
  27. a => a == ($a).map(
  28. d => (d.ord-'0'.ord).int^4
  29. ).sum
  30. ).sum
  31. var a = f()
  32. const b = f()
  33. assert a == b
  34. block:
  35. proc f(): seq[char] =
  36. result = "hello".map(proc(x: char): char = x)
  37. var runTime = f()
  38. const compTime = f()
  39. assert runTime == compTime
  40. # #6083
  41. block:
  42. proc abc(): seq[int] =
  43. result = @[0]
  44. result.setLen(2)
  45. var tmp: int
  46. for i in 0 .. <2:
  47. inc tmp
  48. result[i] = tmp
  49. const fact1000 = abc()
  50. assert fact1000 == @[1, 2]