top_no_cursor2.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. output: '''true
  3. true
  4. true
  5. true
  6. true'''
  7. cmd: "nim c --gc:arc $file"
  8. """
  9. # bug #15361
  10. type
  11. ErrorNodeKind = enum Branch, Leaf
  12. Error = ref object
  13. case kind: ErrorNodeKind
  14. of Branch:
  15. left: Error
  16. right: Error
  17. of Leaf:
  18. leafError: string
  19. input: string
  20. proc ret(input: string, lefterr, righterr: Error): Error =
  21. result = Error(kind: Branch, left: lefterr, right: righterr, input: input)
  22. proc parser() =
  23. var rerrors: Error
  24. let lerrors = Error(
  25. kind: Leaf,
  26. leafError: "first error",
  27. input: "123 ;"
  28. )
  29. # If you remove "block" - everything works
  30. block:
  31. let rresult = Error(
  32. kind: Leaf,
  33. leafError: "second error",
  34. input: ";"
  35. )
  36. # this assignment is needed too
  37. rerrors = rresult
  38. # Returns Error(kind: Branch, left: lerrors, right: rerrors, input: "some val")
  39. # needs to be a proc call for some reason, can't inline the result
  40. var data = ret(input = "some val", lefterr = lerrors, righterr = rerrors)
  41. echo data.left.leafError == "first error"
  42. echo data.left.input == "123 ;"
  43. # stacktrace shows this line
  44. echo data.right.leafError == "second error"
  45. echo data.right.input == ";"
  46. echo data.input == "some val"
  47. parser()