https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

sdeleuze

04/10/2019, 8:02 AM
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

diesieben07

04/10/2019, 8:05 AM
Since the
T
is inferred from the
RowFetchSpec
instance, which is the Java class,
T
automatically becomes a flexible type.
s

sdeleuze

04/10/2019, 8:27 AM
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

diesieben07

04/10/2019, 8:31 AM
Okay, putting it like that is a different thing. Maybe this is a bug, but now I'm in over my head 😄
s

sdeleuze

04/10/2019, 8:54 AM
I have a simple repro, I will create an issue
5 Views