// !LANGUAGE: +VariableDeclarationInWhenSubject // !WITH_NEW_INFERENCE fun foo(s1: Int, s2: Int) = s1 + s2 fun test1(x: String?) = when (val y = x?.length) { null -> 0 else -> foo(x.length, y) } fun test2(x: String?) { when (val y = run { x!! }) { "foo" -> x.length "bar" -> y.length } } fun test3(x: String?, y: String?) { when (val z = x ?: y!!) { "foo" -> x.length "bar" -> y.length "baz" -> z.length } } fun id(x: T): T = x fun test4(x: String?) { when (val y = id(x!!)) { "foo" -> x.length "bar" -> y.length } } class Inv(val data: T) fun test5(x: Inv) { when (val y = x.data) { is String -> y.length // should be ok null -> x.data.length // should be error } } fun test6(x: Inv) { when (val y = x.data) { is String -> x.data.length // should be ok } }