Should smart cast work in case of ```if (myNullabl...
# announcements
j
Should smart cast work in case of
Copy code
if (myNullable?.status in listOf(FOO, BAR)) { <myNullable not nullable here> }
j
I guess not
basically you check if something is in a list
I do not think the compiler is smart enough to check the actual contents of the list
r
well, if the list is nullable, then definitely not otherwise, maybe? I doubt it's working rn (as was mentioned, compiler is probs not smart enuf), but might be a suggestion for improvement
j
well in runtime a list usually loses its type
so not sure if that does anything
r
tho I feel like this is way too complicated for smartcast to be helpful - especially since you would need to think if the list is nullable or not (since they would have diff results), and imho it's better to just state it explicitly @loosing type, isn't smartcast compile time feature? Loosing type in runtime shouldn't matter there
d
There are no smartcasts for such cases because compiler doesn't know semantics of
contains
method. And also there are no method to check that real list implementation that came to
in
doesn't break
contains
contract. Imagine that some custom
List
implementation has some dummy implementation like
operator fun contains(element: Any): Boolean = true
j
Makes sense, thanks. I should have checked what "in" actually does..