summary refs log tree commit diff stats
path: root/tests/arc/top_no_cursor2.nim
blob: 5dfde57aa7dba987ee97d62cf444714082086c7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
discard """
  output: '''true
true
true
true
true'''
  cmd: "nim c --gc:arc $file"
"""
# bug #15361

type
  ErrorNodeKind = enum Branch, Leaf
  Error = ref object
    case kind: ErrorNodeKind
      of Branch:
        left: Error
        right: Error
      of Leaf:
        leafError: string
    input: string

proc ret(input: string, lefterr, righterr: Error): Error =
  result = Error(kind: Branch, left: lefterr, right: righterr, input: input)

proc parser() =
  var rerrors: Error
  let lerrors = Error(
    kind: Leaf,
    leafError: "first error",
    input: "123 ;"
  )
  # If you remove "block" - everything works
  block:
    let rresult = Error(
      kind: Leaf,
      leafError: "second error",
      input: ";"
    )
    # this assignment is needed too
    rerrors = rresult

  # Returns Error(kind: Branch, left: lerrors, right: rerrors, input: "some val")
  # needs to be a proc call for some reason, can't inline the result
  var data = ret(input = "some val", lefterr = lerrors, righterr = rerrors)

  echo data.left.leafError == "first error"
  echo data.left.input == "123 ;"
  # stacktrace shows this line
  echo data.right.leafError == "second error"
  echo data.right.input == ";"
  echo data.input == "some val"

parser()