Closed timotheecour closed 4 years ago
Ok. Any thoughts on how to make it work? Does getTypeImpl
work on such in other contexts?
untried, but maybe something like:
proc process[T](dfl: T) =
when T is ref | ptr:
doAssert dfl != nil # could handle this too maybe
process(dfl[])
elif T is object:
sameAsBefore()
dfl[].getTypeImpl
does not work. What we need is to peel the ref
part of the type off. We may then need either autoderef or a bunch of []
elsewhere in generated code, but the first step is looping over the right .children
.
E.g., it looks like we could do a branch after of ntyObject
of ntyRef: ti = ti[0].getTypeImpl[2]
That actually makes your example compile and even generates the correct help message! Could probably do similar for ptr
and ptr|ref
to tuple types. Running fails in the generated setters, though. We probably just need to set a flag in that branch and elsewhere do the []
conditionally upon that flag. PR welcome if you want to work on it. I won't have time to do more until at least this weekend.
I could be more careful about checking that the T
in ptr|ref T
is an object and this could (maybe?) be generalized to tuples, but the basic usage you were asking for should work. PRs welcome if you want to dot those i's and cross those t's.
@c-blake wonderful, thanks!