summary refs log tree commit diff stats
path: root/tests/closure/tnestedclosure.nim
blob: c8f1e231baab378f7e0ab211bdc81cc246e45afb (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
discard """
  output: '''foo88
23 24foo 88
foo88
23 24foo 88
hohoho'''
"""

# test nested closure
proc main(param: int) =
  var foo = 23
  proc outer(outerParam: string) =
    var outerVar = 88
    echo outerParam, outerVar
    proc inner() =
      block Test:
        echo foo, " ", param, outerParam, " ", outerVar
    inner()
  outer("foo")

# test simple closure within dummy 'main':
proc dummy =
  proc main2(param: int) =
    var foo = 23
    proc outer(outerParam: string) =
      var outerVar = 88
      echo outerParam, outerVar
      proc inner() =
        block Test:
          echo foo, " ", param, outerParam, " ", outerVar
      inner()
    outer("foo")
  main2(24)

dummy()

main(24)

# Jester + async triggered this bug:
proc cbOuter() =
  var response = "hohoho"
  block:
    proc cbIter() =
      block:
        proc fooIter() =
          echo response
        fooIter()
        
    cbIter()

cbOuter()