// !WITH_NEW_INFERENCE // !CHECK_TYPE // See also KT-10896: Wrong inference of if / else result type interface Option class Some : Option class None : Option fun bind(r: Option): Option { return if (r is Some) { // Ideally we should infer Option here (see KT-10896) (if (true) None() else r) checkType { _>() } // Works correctly if (true) None() else r } else r } fun bind2(r: Option): Option { return if (r is Some) { // Works correctly if (true) None() else r } else r } fun bind3(r: Option): Option { return if (r is Some) { // Diagnoses an error correctly if (true) None() else r } else r } fun bindWhen(r: Option): Option { return when (r) { is Some -> { // Works correctly if (true) None() else r } else -> r } } interface SimpleOption class SimpleSome : SimpleOption class SimpleNone : SimpleOption fun bindNoGeneric(r: SimpleOption): SimpleOption { return if (r is SimpleSome) { (if (true) SimpleNone() else r) checkType { _() } if (true) SimpleNone() else r } else r }