I have a Coroutines extension leveraging some Java...
# coroutines
s
I have a Coroutines extension leveraging some Java methods specified as
suspend fun <T : Any> RowsFetchSpec<T>.awaitOne(): T = one().awaitSingle()
but when it used, type inference shows
T!
, what did I miss? I have specified that
T
extends non nullable
Any
so I would expect return type
T
.
message has been deleted
d
Since the
T
is inferred from the
RowFetchSpec
instance, which is the Java class,
T
automatically becomes a flexible type.
s
Hum, I am pretty sure that I used
<T : Any>
for non suspending extensions to enforce return type non-nullability. And even when I use
suspend fun <T> RowsFetchSpec<T>.awaitOne() = one().awaitSingle()!!
the inferred type on usage side is still
T!
while it is shown as
T
on extension definition side.
I am suspecting an issue related to Java interop + extensions + suspending functions.
Otherwise, how can I define this extension to return a non nullable type? What could be more explicit than
suspend fun <T> RowsFetchSpec<T>.awaitOne() = one().awaitSingle()!!
?
d
Okay, putting it like that is a different thing. Maybe this is a bug, but now I'm in over my head 😄
s
I have a simple repro, I will create an issue