mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
* enable stricteffects * add gcsafe * fix tests * use func * fixes pegs tests * explicitly mark repr related procs with noSideEffect * add nimLegacyEffects * change URL * fixes docopt * add `raises: []` to repr * fixes weave * fixes nimyaml * fixes glob * fixes parsetoml * Apply suggestions from code review * Update testament/important_packages.nim * add legacy:laxEffects
25 lines
514 B
Nim
25 lines
514 B
Nim
block: # `.noSideEffect`
|
|
func foo(bar: proc(): int): int {.effectsOf: bar.} = 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)
|