I want to check if variable is a specific type of proc. For example:
proc test(a: int): int = discard
echo test is proc (a: int): int
However this code counter-intuitively returns false. So how do I check this?
This is somehow very broken, take a look:
proc test(a: int): int = discard
echo typeof(test)
echo test is typeof(test)
echo test is proc (a: int): int{.noSideEffect, gcsafe, locks: 0.}
This prints out:
proc (a: int): int{.noSideEffect, gcsafe, locks: 0.}
true
false
Calling conversions didn't match.
proc test(a: int): int = discard
echo test is (proc (a: int): int {.nimcall.}) #true
Normal procs that's not variables are default to {.nimcall.}, but as a variable type, proc is default to {.closure.}.To explain it:
proc f(): int = discard #default to `{.nimcall.}`
echo f is proc(): int {.closure.} #false
echo f is proc(): int {.nimcall.} #true
echo f is proc(): int #false; `proc(): int` is default to `{.closure.}` when used as a type.
Anyway I don't think it's a bug, as it follows the definition of the language. The problem is that such rules are not strightforward.