this is curious.. I have the following ``` infix o...
# intellij
e
this is curious.. I have the following
Copy code
infix operator fun <N> N.minus(other: N): N where N : Number, N : Comparable<N> =
        when {
            this is Byte && other is Byte -> this - other
            this is Short && other is Short -> this - other
            this is Int && other is Int -> this - other
//            this is Long && other is Long -> this - other
//            this is Float && other is Float -> this - other
            else -> error("Invalid operand types")
        } as N
Everything works fine, smart casting is kicking in properly. However if I comment out one the last two lines, then it cast automatically the result to
Any
... ??
k
Not really #intellij.
What two lines do you comment away exactly?
e
what do you suggest?
k
Just #general I guess.
e
the ones that are commented right now
k
Ah you're right, this might be #intellij
e
😄
k
Ah no it does make sense,
-
on
Byte
and
Short
returns an
Int
.
e
?
k
Copy code
val x: Byte = ...
val y: Byte = ...
val r = x - y
r
has type
Int
.
e
got it
thanks
k
No problem. simple smile