Is there any way to make a function such as `handl...
# announcements
t
Is there any way to make a function such as
handleBox
typecheck without unsafe casting?
l
but why you need to have the
abstract val value
in the first place ?
wait, got it.
k
Isn't
box
smartcasted to
IntBox
?
a
yes it is, but the compiler doesn't realize that
T
has the same type as
box.value
k
Does something like
Copy code
val box: Box = ...
if (box is IntBox)
    println(box.value * 2)
also not work?
a
that works fine, the problem is that
when(box) { .. }
has the return type
Any
instead of
T
k
Damm missed the return part, okay that makes sense.
a
1.3 added new type inference to better support intersection types
Int & String
, maybe we get sum types
Int | T
with 1.4? 🧌
k
I remember there being a youtrack issue similar to this, can't find it though.
@Andreas Sinz lots of us would like that!
a
BTT, @toxara its not possible right now