you can actually overload the . operator (and maybe the .= and .() ones as
well) to do this. You can have a macro that goes through the children and
selects the one that matches. A cool side effect of doing things this way is
that the memory layout of the object is much more obvious and you can control
which things come from where. A well maintained nimble library for doing this
would be nice, as it's easy to generate somewhat hard to understand errors, and
edge cases. There's subfield but it applies to EVERYTHING and thus causes
unwanted side-effects (and can blow out the compiler by going down type after
type).
to be honest this:
type base1 = object
f1: int
f2: float
type base2 = object
f3: string
type child = object {.child: thing1, thing2.}
thing1: base1
thing2: base2
seems quite nice to me. And it decouples use of OO for virtual dispatch from
it's use for composition (remember inheritance IS composition with some funky
rules!). It will also make construction order very obvious