tdistinctseq.nim 635 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. matrix: "-u:nimPreviewNonVarDestructor;"
  3. """
  4. type DistinctSeq* = distinct seq[int]
  5. # `=destroy`(cast[ptr DistinctSeq](0)[])
  6. var x = @[].DistinctSeq
  7. `=destroy`(x)
  8. import std/options
  9. # bug #24801
  10. type
  11. B[T] = object
  12. case r: bool
  13. of false:
  14. v: ref int
  15. of true:
  16. x: T
  17. E = distinct seq[int]
  18. U = ref object of RootObj
  19. G = ref object of U
  20. proc a(): E = default(E)
  21. method c(_: U): seq[E] {.base.} = discard
  22. proc p(): seq[E] = c(default(U))
  23. method c(_: G): seq[E] = discard E(newSeq[seq[int]](1)[0])
  24. method y(_: U) {.base.} =
  25. let s = default(B[tuple[f: B[int], w: B[int]]])
  26. discard some(s.x)