See:
type MyPointer = distinct pointer
proc foo(a: MyPointer) =
echo repr(a)
foo(cast[MyPointer](1))
foo(cast[MyPointer](nil))
foo(nil) # how to make that work?
Is it possible to allow nil for distinct pointer types like in the example? It works when I remove the disctinct but thats not what I want.
I also could not figure out if it is possible to write a converter which converts "any nil" to a "specific nil"
Something like:
converter toMyPointer(x: NilType): MyPointer = MyPointer(nil)
I solved it so far by defining a "NilType" myself and write converters for that like the following:
type MyNil = distinct pointer
const myNil* = MyNil(nil)
type MyPointer = distinct pointer
proc foo(a: MyPointer) =
echo repr(a)
converter toMyPointer(x: MyNil): MyPointer = MyPointer(nil)
foo(cast[MyPointer](1))
foo(myNil) # My own nil :)
Works for what its needed but still can't use "nil" in the proc calls.