Holy moly. What witchcraft is this? IntelliJ will,...
# intellij
r
Holy moly. What witchcraft is this? IntelliJ will, on an await call, actually statically check the job that you're awaiting, and give you an "Unreachable Code" warning if that job will always fail? That's either some very specific inspection or some seriously impressive general static analysis
d
I haven’t checked, but I’m pretty sure that it’s actually neither of these — it’s the smart type system and inference 🙂 I guess that
async
returns something like
Deferred<T>
, and
Deferred<T>.await
returns
T
. Then,
throw Exception()
actually has type in Kotlin — it’s
Nothing
. So, type of
job2
is
Deferred<Nothing>
and
job2.await()
returns
Nothing
. Now, the compiler is smart and knows that you can’t get a value of type
Nothing
, so if something appears to return
Nothing
, it actually means that the execution flow is interrupted (e.g. by exception)
r
Ohhh, of course, that's it 🤦 I continue being amazed by kotlin's type system 😄
Thanks for pointing that out!
d
No problem, that’s actually non-trivial interaction 🙂
p
It's actually pretty trivial
Rule 1: sth that just throws returns a nothing
Rule 2: everything after nothing is unreachable
Almost all inspections are trivial, that's why they are so genious when they play together like this :)
d
Yeah, that’s actually what I wanted to say, but failed to 😅 All pieces individually are not that complicated, but they play nicely together and sometimes cover quite non-trivial cases 🙂