tissues.nim 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import macros
  2. block t9043: # bug #9043
  3. proc foo[N: static[int]](dims: array[N, int]): string =
  4. const N1 = N
  5. const N2 = dims.len
  6. const ret = $(N, dims.len, N1, N2)
  7. static: doAssert ret == $(N, dims.len, N1, N2)
  8. ret
  9. doAssert foo([1, 2]) == "(2, 2, 2, 2)"
  10. block t4952:
  11. proc doCheck(tree: NimNode) =
  12. let res: tuple[n: NimNode] = (n: tree)
  13. assert: tree.kind == res.n.kind
  14. for sub in tree:
  15. doCheck(sub)
  16. macro id(body: untyped): untyped =
  17. doCheck(body)
  18. id(foo((i: int)))
  19. static:
  20. let tree = newTree(nnkExprColonExpr)
  21. let t = (n: tree)
  22. doAssert: t.n.kind == tree.kind
  23. # bug #19909
  24. type
  25. SinglyLinkedList[T] = ref object
  26. SinglyLinkedListObj[T] = ref object
  27. proc addMoved[T](a, b: var SinglyLinkedList[T]) =
  28. if a.addr != b.addr: discard
  29. proc addMoved[T](a, b: var SinglyLinkedListObj[T]) =
  30. if a.addr != b.addr: discard
  31. proc main =
  32. var a: SinglyLinkedList[int]; new a
  33. var b: SinglyLinkedList[int]; new b
  34. a.addMoved b
  35. var a0: SinglyLinkedListObj[int]
  36. var b0: SinglyLinkedListObj[int]
  37. a0.addMoved b0
  38. static: main()
  39. # bug #18641
  40. type A = object
  41. ha1: int
  42. static:
  43. var a = A()
  44. var a2 = a.addr
  45. a2.ha1 = 11
  46. doAssert a2.ha1 == 11
  47. a.ha1 = 12
  48. doAssert a.ha1 == 12
  49. doAssert a2.ha1 == 12 # ok
  50. static:
  51. proc fn() =
  52. var a = A()
  53. var a2 = a.addr
  54. a2.ha1 = 11
  55. doAssert a2.ha1 == 11
  56. a.ha1 = 12
  57. doAssert a.ha1 == 12
  58. doAssert a2.ha1 == 12 # fails
  59. fn()