Thread
#reflect
    j

    jw

    2 weeks ago
    is it possible to determine if a lambda type has a receiver or just a normal argument from parsing a function parameter's type? i'm in the process of switching from reflect to metadata-jvm (or maybe fully blown UAST) but looking for a quick workaround until then
    The
    KParameterImpl
    has the
    KFunctionImpl
    in its private
    callable
    property, but I can't get access to that as far as I can tell
    Oh nevermind that's the enclosing function
    e

    ephemient

    2 weeks ago
    without metadata, I believe
    (T) -> R
    and
    T.() -> R
    are represented by the same
    kotlin.Function1<T, R>
    which is erased to
    kotlin.jvm.internal.Function1
    on JVM: https://github.com/JetBrains/kotlin/blob/master/spec-docs/function-types.md
    j

    jw

    2 weeks ago
    They are, but kotlin-reflect uses metadata, right? That's why it's like 20MiB or whatever because it embeds all the protos.
    e

    ephemient

    2 weeks ago
    oh I thought you were looking for a way to do it without metadata-jvm. hmm, seems like you should be able to do it with metadata but it's not obvious to me how
    j

    jw

    2 weeks ago
    yeah i think i just need to fully abandon "runtime" reflection and switch to metadata-jvm parsing of the class files
    solves more problems than just this current one
    e

    ephemient

    2 weeks ago
    kotlin.reflect.typeOf<Unit.() -> Unit>() == kotlin.reflect.typeOf<(Unit) -> Unit>()
    I don't think kotlin-reflect exposes any difference 😕
    j

    jw

    2 weeks ago
    I think you can!
    type.annotations.any { it.annotationClass == ExtensionFunctionType::class }
    e

    ephemient

    2 weeks ago
    >>> fun f(block: (Unit) -> Unit) = Unit
    >>> fun g(block: Unit.() -> Unit) = Unit
    >>> ::f.parameters.single().type.annotations
    res0: List<Annotation> = []
    >>> ::g.parameters.single().type.annotations
    res1: List<Annotation> = [@kotlin.ExtensionFunctionType()]
    >>> ::f.parameters.single().type == ::g.parameters.single().type
    res2: Boolean = true
    >>> typeOf<Unit.() -> Unit>().annotations
    res3: List<Annotation> = []
    … ok, I guess that works, but it's kinda surprising
    j

    jw

    2 weeks ago
    e

    ephemient

    2 weeks ago
    looks like there's also
    @kotlin.ContextFunctionTypeParams(count: Int)
    and
    @kotlin.ParameterName(name: String)
    (the latter on the type parameters to
    FunctionN<>
    ), and the lambda type also seems to know if it's a
    suspend
    function, but I'm not sure how that's determined
    that's actually a pretty decent amount of information without having to pull kotlinx-metadata-jvm yourself