Hi,
I want to declare a function that takes another one as its parameter.
func someFunc(f: func(): bool): bool =
f()
So I expect someFunc and f to have the noSideEffect pragma.
import std/typetraits
echo someFunc.type()
But only someFunc has it, not its parameter.
proc (f: proc (): bool{.closure.}): bool{.noSideEffect, gcsafe, locks: <unknown>.}
Speaking of side effect, this affects lambdas too.
echo type(func (): bool)
proc (): bool{.closure.}
So, is it a bug ?
Although it is not a big deal since the first func in someFunc enforces f to have no side effects.
Seems like a bug
func someFunc(f: func(): bool {.nimcall, noSideEffect.}): bool =
f()
echo someFunc.type() # proc (f: proc (): bool{.noSideEffect.}): bool{.noSideEffect, gcsafe, locks: 0.}
Thanks for the reply.
func someFunc(f: func(): bool {.nimcall, noSideEffect.}): bool =
f()
This is the workaround I use (nimcall or closure) and it does the job, though a bit repetitive.
I forgot to tell the compiler version I used: 0.19.4.