tmagics.nim 1000 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 #12229
  50. proc foo(T: typedesc) = discard
  51. foo(ref)