proc test(C: typedesc, testProc: proc(arg: int) = nil) =
echo("ok")
test(int) # "ok"
... but this doesn't?
proc test(C: typedesc, testProc: proc(arg: C) = nil) =
echo("ok")
test(int) # Error
Error: execution of an external compiler program 'gcc -c -w -I/usr/lib/nim -o .../nimcache/main.o .../nimcache/main.c' failed with exit code: 256 In file included from .../nimcache/main.c:9:0: .../nimcache/main.c: In function ‘main_194051’: /usr/lib/nim/nimbase.h:224:19: error: incompatible type for argument 1 of ‘test_194058’ # define NIM_NIL ((void*)0) /* C's NULL is fucked up in some C compilers, so ^ .../nimcache/main.c:398:14: note: in expansion of macro ‘NIM_NIL’ test_194058(NIM_NIL); ^ In file included from .../nimcache/main.c:9:0: .../nimcache/main.c:242:17: note: expected ‘TY194063 {aka struct <anonymous>}’ but argument is of type ‘void *’ N_NIMCALL(void, test_194058)(TY194063 testproc) { ^ /usr/lib/nim/nimbase.h:173:44: note: in definition of macro ‘N_NIMCALL’ # define N_NIMCALL(rettype, name) rettype name /* no modifier */ ^
This is a bug, you should report it to https://github.com/nim-lang/Nim/issues
Now, if you want to make your snippet work, there is a workaround:
proc test(C: typedesc, testProc: proc(arg: C)) =
echo("ok")
proc test(C: typedesc) =
test(C, nil)
test(int)
test(int, proc(i: int) = discard)