t13062.nim 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. discard """
  2. matrix: "--mm:refc; --mm:orc"
  3. targets: "c cpp"
  4. """
  5. import atomics
  6. type
  7. Pledge* {.exportc.} = object
  8. p: PledgePtr
  9. PledgeKind {.exportc.} = enum
  10. Single
  11. Iteration
  12. PledgePtr {.exportc.} = ptr object
  13. case kind: PledgeKind
  14. of Single:
  15. impl: PledgeImpl
  16. of Iteration:
  17. discard
  18. PledgeImpl {.exportc.} = object
  19. fulfilled: Atomic[bool]
  20. var x: Pledge
  21. when defined(cpp):
  22. # TODO: fixme
  23. discard "it doesn't work for refc/orc because of contrived `Atomic` in cpp"
  24. elif defined(gcRefc):
  25. doAssert x.repr == "[p = nil]"
  26. else: # fixme # bug #20081
  27. doAssert x.repr == "Pledge(p: nil)"
  28. block:
  29. block: # bug #18081
  30. type
  31. Foo = object
  32. discard
  33. Bar = object
  34. x: Foo
  35. proc baz(state: var Bar) =
  36. state.x = Foo()
  37. baz((ref Bar)(x: (new Foo)[])[])
  38. block: # bug #18079
  39. type
  40. Foo = object
  41. discard
  42. Bar = object
  43. x: Foo
  44. proc baz(state: var Bar) = discard
  45. baz((ref Bar)(x: (new Foo)[])[])
  46. block: # bug #18080
  47. type
  48. Foo = object
  49. discard
  50. Bar = object
  51. x: Foo
  52. proc baz(state: var Bar) = discard
  53. baz((ref Bar)(x: Foo())[])