tbasics.nim 763 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. discard """
  2. output: '''ABCDC
  3. 1
  4. 14
  5. ok
  6. 1'''
  7. """
  8. type
  9. MyEnum = enum
  10. A,B,C,D
  11. # trick the optimizer with an seq:
  12. var x = @[A,B,C,D]
  13. echo x[0],x[1],x[2],x[3],MyEnum(2)
  14. # bug #10651
  15. var xa: seq[int]
  16. var ya = @[1,2]
  17. xa &= ya
  18. echo xa[0]
  19. proc test =
  20. var yup: seq[int]
  21. try:
  22. yup.add 14
  23. echo yup.pop
  24. finally:
  25. discard
  26. test()
  27. when true:
  28. var a: seq[int]
  29. a.setLen(0)
  30. echo "ok"
  31. # bug #10697
  32. proc test2 =
  33. var val = uint16(0)
  34. var i = 0
  35. if i < 2:
  36. val += uint16(1)
  37. echo int(val)
  38. test2()
  39. var someGlobal = default(array[5, int])
  40. for x in someGlobal: doAssert(x == 0)
  41. proc tdefault =
  42. var x = default(int)
  43. doAssert(x == 0)
  44. proc inner(v: openArray[string]) =
  45. doAssert(v.len == 0)
  46. inner(default(seq[string]))
  47. tdefault()