Files
kotlin-fork/compiler/testData/diagnostics/tests/when/withSubjectVariable/smartCastOnValueBoundToSubjectVariable.kt
T
Dmitry Petrov 5f0c9490bb Add test for smart cast on a value bound to when subject variable
E.g.:
  when (val y = x?.foo()) {
    null -> ...
    else -> ... // 'x' is also non-null here
  }
2018-06-20 14:06:34 +03:00

9 lines
282 B
Kotlin
Vendored

// !LANGUAGE: +VariableDeclarationInWhenSubject
fun foo(s1: String, s2: String) = s1 + s2
fun test(x: Any?) =
when (val y = x?.toString()) {
null -> "null"
else -> foo(<!DEBUG_INFO_SMARTCAST!>x<!>.toString(), <!DEBUG_INFO_SMARTCAST!>y<!>)
}