fix manual to reflect reality for .nosideeffect (#16781)
This commit is contained in:
parent
aca97250ea
commit
8f62cd512c
2 changed files with 49 additions and 6 deletions
24
tests/effects/tnosideeffect.nim
Normal file
24
tests/effects/tnosideeffect.nim
Normal file
|
|
@ -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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue