Is there any easy way in KSP to get the closest co...
# ksp
j
Is there any easy way in KSP to get the closest common ancestor of two
KSType
? I’m doing the resolution with a hand-written algorithm right now and it feels wrong
For example, say I have a
KSType
of
Either<Nothing, Int>
and another of
Either<Throwable, Nothing>
, I want to infer that their common ancestor is
Either<Throwable, Int>
j
It doesn’t really work as a common ancestor, you need to have variance in order to make it a common ancestor, for example you need to have
Either<out T, out P>
declared. Even after that, you still need to manually write a least common ancestor algorithm to determine the common ancestor you are looking for, and you also need to deal it with recursively as the type arguments can still be generics.
j
In this example Either is defined as
Either<out E, out T>
so I think the ancestor exists. I guess I was hoping KSP already had a least common ancestor implementation but it sounds like I'll need to roll my own 🙂
j
ah yes, you need to implement it yourself. This is not a common enough use case to be included in public API.
👍 1