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
  }
This commit is contained in:
Dmitry Petrov
2017-10-23 08:58:51 +03:00
parent 0a0bc67e8a
commit 5f0c9490bb
4 changed files with 25 additions and 0 deletions
@@ -0,0 +1,9 @@
// !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<!>)
}
@@ -0,0 +1,4 @@
package
public fun foo(/*0*/ s1: kotlin.String, /*1*/ s2: kotlin.String): kotlin.String
public fun test(/*0*/ x: kotlin.Any?): kotlin.String