I am not sure if my code is valid (without last line, it can compile and run)
import typetraits
type
Parent {.inheritable.} = object
Child = object of Parent
proc super(_: typedesc[Parent]): typedesc = typedesc[void]
proc super(_: typedesc[Child]): typedesc = typedesc[Parent]
echo Parent.name
echo Child.name
#echo Child.super.name
The last line is compile with error
Error: expression 'super(Child)' has no type (or is ambiguous)
Well you could use template instead of proc there, but that's very tedious to maintain and this is just easier.
import std/macros
type
Parent {.inheritable.} = object
Child = object of Parent
macro parent(typ: typedesc): untyped =
let impl = typ.getImpl
assert impl[^1].kind == nnkObjectTy and impl[^1][1].kind == nnkOfInherit, "Type is not a child obj"
result = impl[^1][1][0]
echo Parent
echo Child
echo Child.parent
With template, it can build and run as expected
import typetraits
type
Parent {.inheritable.} = object
Child = object of Parent
template super(_: typedesc[Parent]): typedesc = typedesc[void]
template super(_: typedesc[Child]): typedesc = typedesc[Parent]
echo Parent.name
echo Child.name
echo Child.super.name