diff options
Diffstat (limited to 'tests/discard/tdiscardable.nim')
-rw-r--r-- | tests/discard/tdiscardable.nim | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/discard/tdiscardable.nim b/tests/discard/tdiscardable.nim index 032050139..84b669ed8 100644 --- a/tests/discard/tdiscardable.nim +++ b/tests/discard/tdiscardable.nim @@ -5,6 +5,7 @@ tdiscardable 1 something defered something defered +hi ''' """ @@ -65,3 +66,110 @@ proc main2() = main1() main2() + +block: # bug #13583 + block: + proc hello(): int {.discardable.} = 12 + + iterator test(): int {.closure.} = + while true: + hello() + + let t = test + + block: + proc hello(): int {.discardable.} = 12 + + iterator test(): int {.closure.} = + while true: + block: + yield 12 + hello() + + let t = test + doAssert t() == 12 + + block: + proc hello(): int {.discardable.} = 12 + + iterator test(): int {.closure.} = + while true: + yield 12 + hello() + + let t = test + doAssert t() == 12 + +block: + proc bar(): string {.discardable.} = + "15" + + proc foo(): int = + while true: + raise newException(ValueError, "check") + 12 + + doAssertRaises(ValueError): + doAssert foo() == 12 + +block: # issue #10440 + proc x(): int {.discardable.} = discard + try: + x() + finally: + echo "hi" + +import macros + +block: # issue #14665 + macro test(): untyped = + let b = @[1, 2, 3, 4] + + result = nnkStmtList.newTree() + var i = 0 + while i < b.len: + if false: + # this quote do is mandatory, removing it fixes the problem + result.add quote do: + let testtest = 5 + else: + result.add quote do: + let test = 6 + inc i + # removing this continue fixes the problem too + continue + inc i + test() + +block: # bug #23775 + proc retInt(): int {.discardable.} = + 42 + + proc retString(): string {.discardable.} = + "text" + + type + Enum = enum + A, B, C, D + + proc doStuff(msg: Enum) = + case msg: + of A: + retString() + of B: + retInt() + of C: + discard retString() + else: + let _ = retString() + + doStuff(C) + +block: + proc test(): (int, int) {.discardable.} = + discard + + if true: + test() + else: + quit() |