do something is SubB -> … // do something else -> … // fatal error? makeshift code? }.let { … } !!: Only when treating "when" as an expression, checked whether it covers all. switch-case expression noise… Kotlin
… // do something case let b as SubB: … // do something default: … // fatal error? makeshift code? } noise… Even if the premise is broken, we can not detect statically. Swift Inhibit the representation that it covers the whole type in the context :(
let item as Book: // do something // use item as Book case let item as Memo: // do something // use item as Memo default: assertionFailure("unexpected type: \(item)") } } noise…
do something is SubB -> … // do something else -> … // fatal error? makeshift code? }.let { … } !!: Only when treating "when" as an expression, checked whether it covers all. switch-case expression Kotlin
do something is Super.SubB -> … // do something else -> … // fatal error? makeshift code? }.let { … } noise… Kotlin !!: Only when treating "when" as an expression, checked whether it covers all.
case let item as Book: // do something // use item as Book case let item as Memo: // do something // use item as Memo default: assertionFailure("unexpected type: \(item)") } } noise…
// do something // use item as Book case .memo(let memo): // do something // use item as Memo default: assertionFailure("unexpected type: \(item)") } } Swift noise…
// do something // use item as Book case .memo(let memo): // do something // use item as Memo default: assertionFailure("unexpected type: \(item)") } } Swift noise…
{ switch item { case let item as Book: // do something // use item as Book case let item as Memo: // do something // use item as Memo default: assertionFailure("unexpected type: \(item)") } } } Swift before