forked from nim-lang/Nim
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix manual to reflect reality for .nosideeffect (nim-lang#16781)
- Loading branch information
1 parent
ac37555
commit a4a12f2
Showing
2 changed files
with
49 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |