Hey, Kotlin poet question - is there a way to prev...
# squarelibraries
k
Hey, Kotlin poet question - is there a way to prevent typealias imports for functions being resolved into kotlin.FunctionX types? Having
typealias Fn0<R> = () -> R
and changing it className (via
::class.toClassName
), results in actual usage of
kotlin.Function0
d
I don't think so. KotlinPoet would have to internally map
kotlin.Function0
and friends to
LambdaTypeName
in, for example,
toTypeName
, but that would probably be unexpected for someone who did literally want
Function0
. I say it would have to happen in
toTypeName
rather than
toClassName
since when you use
::class
, you are getting the
KClass
, which is the
kotlin.Function0
class. If you use
toClassName
, you are going to get a
ClassName
and not a
LambdaTypeName
. You could probably write your own function to do this (by using
typeOf
) but it's a lossy transformation anyway, since receiver types are not represented in
kotlin.Function*
(they are just regular parameters). So you might as well use
LambdaTypeName
j
Right. It's the Kotlin compiler that is resolving the typealias here, not KotlinPoet.
k
thank you both, that totally make sense 🙏 Thanks @damian for insight, I have few ideas how to make it work