Hey people, this is more of a type system question...
# coroutines
m
Hey people, this is more of a type system question rather than a coroutines question per se, but are the suspend lambdas function types non-denotable types in Kotlin?
Or if alternatively someone could point me to the correct channel to ask this type of question 🙏
j
Lambdas are not really types themselves. Lambdas are one way to write expressions that represent values of a function type. Function types are denotable, and suspending function types as well. You just need to add
suspend
in front of a regular function type:
suspend () -> Unit
is an example of a suspending function type. You can see this sort of types in the declarations of some higher-order functions in the coroutines library, typically coroutine builders like
launch
or `async`: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/launch.html
👍 1
m
> Lambdas are not really types themselves Yeah, fair, I was referring to suspending function type. Sorry, I should’ve expressed my initial question better. Here’s the reason why I ask. Consider the following code:
Copy code
@JvmInline
value class DummySuspendValue(val block: suspend () -> Unit)

...

val a = DummySuspendValue {}
val classifier = a::class.declaredMemberProperties.first().returnType.classifier
In the example above, classifier is
null
. According to the docs, `classifier`:
Returns null if this type is not denotable in Kotlin, for example if it is an intersection type.
If I were to go by the reflection behaviour and the docs, I’d have to conclude that a suspending function type is in fact non-denotable. If I remove the suspend modifier like so:
Copy code
@JvmInline
value class DummySuspendValue(val block: () -> Unit)
the classifier is no longer
null
.