spand
12/04/2019, 8:25 AMsealed class Sc {
object Foo : Sc()
}
fun (sc: Sc){
when (sc){
Sc.Foo -> sc // <-- type is still Sc here, not Foo
}
}
Seems like a basic case but I couldnt even find an issue on youtrack about itJaymin.Kim
12/04/2019, 8:28 AMis Sc.Foo -> sc
?spand
12/04/2019, 8:29 AMJaymin.Kim
12/04/2019, 8:31 AMif (sc == Sc.Foo)
not working
if (sc === Sc.Foo)
workingdmitriy.novozhilov
12/04/2019, 8:32 AMequals
can be overriden, so equality doesn't guarantees that sc
is really Sc.Foo
sealed class Sc {
object Foo : Sc() {
fun bar() {}
}
class FakeFoo : Sc() {
override fun equals(other: Any?): Boolean {
return true
}
}
}
fun foo(){
val sc: Sc = Sc.FakeFoo()
when (sc) {
Sc.Foo -> sc
}
// this when is equal to such if
// where `equals` is called
if (sc == Sc.Foo) { // it's true
sc
}
}
diesieben07
12/04/2019, 8:36 AMspand
12/04/2019, 8:36 AMKroppeb
12/04/2019, 8:53 AMSc.Foo
instead of sc
as a fix.spand
12/04/2019, 8:56 AM