Joshua Hannaford
07/19/2023, 3:20 PMreadText
even after the cast in the line above?
for (frame in incoming) {
frame as? Frame.Text ?: continue
val receivedText = frame.readText() // No autocomplete here
send("You said: $receivedText")
}
I'm going through the KTOR creating web socket chat tutorial and thought it was broken because it didn't give autocomplete for readText
. It would only give readBytes
for a general Frame
.Joshua Hannaford
07/19/2023, 3:25 PMfor (frame in incoming) {
val f = frame as? Frame.Text ?: continue
val receivedText = f.readText()
send("You said: $receivedText")
}
ephemient
07/19/2023, 3:36 PMNote that smart casts work only when the compiler can guarantee that the variable won't change between the check and the usage.
ephemient
07/19/2023, 3:38 PMfor (frame in
should count as a local val
bind, so that's strange…Joshua Hannaford
07/19/2023, 3:40 PMis
keyword works as expected as well
for (frame in incoming) {
if (frame !is Frame.Text) continue
val receivedText = frame.readText()
send("You said: $receivedText")
}
Klitos Kyriacou
07/19/2023, 3:41 PMframe.readText()
is not a compilation error, but just no autocomplete. Therefore it looks like an IntelliJ bug.