tmagics.nim 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. discard """
  2. matrix: "--mm:refc"
  3. output: '''
  4. true
  5. true
  6. false
  7. true
  8. true
  9. false
  10. true
  11. '''
  12. joinable: false
  13. """
  14. block tlowhigh:
  15. type myEnum = enum e1, e2, e3, e4, e5
  16. var a: array[myEnum, int]
  17. for i in low(a) .. high(a):
  18. a[i] = 0
  19. proc sum(a: openArray[int]): int =
  20. result = 0
  21. for i in low(a)..high(a):
  22. inc(result, a[i])
  23. doAssert sum([1, 2, 3, 4]) == 10
  24. block t8693:
  25. type Foo = int | float
  26. proc bar(t1, t2: typedesc): bool =
  27. echo (t1 is t2)
  28. (t2 is t1)
  29. proc bar[T](x: T, t2: typedesc): bool =
  30. echo (T is t2)
  31. (t2 is T)
  32. doAssert bar(int, Foo) == false
  33. doAssert bar(4, Foo) == false
  34. doAssert bar(any, int)
  35. doAssert bar(int, any) == false
  36. doAssert bar(Foo, Foo)
  37. doAssert bar(any, Foo)
  38. doAssert bar(Foo, any) == false
  39. block t9442:
  40. var v1: ref char
  41. var v2: string
  42. var v3: seq[char]
  43. GC_ref(v1)
  44. GC_unref(v1)
  45. GC_ref(v2)
  46. GC_unref(v2)
  47. GC_ref(v3)
  48. GC_unref(v3)
  49. block: # bug #6499
  50. let x = (chr, 0)
  51. doAssert x[1] == 0
  52. block: # bug #12229
  53. proc foo(T: typedesc) = discard
  54. foo(ref)