| 1 | @[has_globals] |
| 2 | module main |
| 3 | |
| 4 | __global fcall_count = int(0) |
| 5 | |
| 6 | fn f1() { |
| 7 | println(1) |
| 8 | fcall_count++ |
| 9 | } |
| 10 | |
| 11 | fn f2() { |
| 12 | println(2) |
| 13 | fcall_count++ |
| 14 | } |
| 15 | |
| 16 | fn f3(f fn ()) { |
| 17 | f() |
| 18 | } |
| 19 | |
| 20 | fn func_defer() { |
| 21 | mut func := f1 |
| 22 | println('Before') |
| 23 | defer { |
| 24 | func() |
| 25 | } |
| 26 | defer { |
| 27 | f3(func) |
| 28 | } |
| 29 | func = f2 |
| 30 | println('After') |
| 31 | assert true |
| 32 | } |
| 33 | |
| 34 | fn test_defer_with_fn_var() { |
| 35 | func_defer() |
| 36 | assert fcall_count == 2 |
| 37 | } |
| 38 |