summary refs log tree commit diff stats
path: root/tests/effects
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-01-22 11:04:48 -0800
committerGitHub <noreply@github.com>2021-01-22 20:04:48 +0100
commit8f62cd512c0c5ae9a27087ccf8b4f666611709e6 (patch)
tree0e2eb7135212d1ff130a00d29016381ec0057d60 /tests/effects
parentaca97250eae891c87e0c98f02bd7db9687bab5b0 (diff)
downloadNim-8f62cd512c0c5ae9a27087ccf8b4f666611709e6.tar.gz
fix manual to reflect reality for .nosideeffect (#16781)
Diffstat (limited to 'tests/effects')
-rw-r--r--tests/effects/tnosideeffect.nim24
1 files changed, 24 insertions, 0 deletions
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)