From 8f62cd512c0c5ae9a27087ccf8b4f666611709e6 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Fri, 22 Jan 2021 11:04:48 -0800 Subject: fix manual to reflect reality for .nosideeffect (#16781) --- tests/effects/tnosideeffect.nim | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/effects/tnosideeffect.nim (limited to 'tests/effects') diff --git a/tests/effects/tnosideeffect.nim b/tests/effects/tnosideeffect.nim new file mode 100644 index 000000000..9cabb35a2 --- /dev/null +++ b/tests/effects/tnosideeffect.nim @@ -0,0 +1,24 @@ +block: # `.noSideEffect` + func foo(bar: proc(): int): int = bar() + var count = 0 + proc fn1(): int = 1 + proc fn2(): int = (count.inc; count) + + template accept(body) = + doAssert compiles(block: + body) + + template reject(body) = + doAssert not compiles(block: + body) + + accept: + func fun1() = discard foo(fn1) + reject: + func fun1() = discard foo(fn2) + + var foo2: type(foo) = foo + accept: + func main() = discard foo(fn1) + reject: + func main() = discard foo2(fn1) -- cgit 1.4.1-2-gfad0