Extra tests for when with val in subject
This commit is contained in:
Vendored
+1
-1
@@ -3,7 +3,7 @@
|
||||
|
||||
fun foo(): Any = 42
|
||||
|
||||
fun test(x: Any) {
|
||||
fun test1(x: Any) {
|
||||
when (val y = foo()) {
|
||||
is String -> <!VAL_REASSIGNMENT!>y<!> = ""
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Any
|
||||
public fun test(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
public fun test1(/*0*/ x: kotlin.Any): kotlin.Unit
|
||||
|
||||
+45
-6
@@ -1,9 +1,48 @@
|
||||
// !LANGUAGE: +VariableDeclarationInWhenSubject
|
||||
|
||||
fun foo(s1: String, s2: String) = s1 + s2
|
||||
fun foo(s1: Int, s2: Int) = s1 + s2
|
||||
|
||||
fun test(x: Any?) =
|
||||
when (val y = x?.toString()) {
|
||||
null -> "null"
|
||||
else -> foo(<!DEBUG_INFO_SMARTCAST!>x<!>.toString(), <!DEBUG_INFO_SMARTCAST!>y<!>)
|
||||
}
|
||||
fun test1(x: String?) =
|
||||
when (val y = x?.length) {
|
||||
null -> 0
|
||||
else -> foo(<!DEBUG_INFO_SMARTCAST!>x<!>.length, <!DEBUG_INFO_SMARTCAST!>y<!>)
|
||||
}
|
||||
|
||||
fun test2(x: String?) {
|
||||
when (val y = run { x!! }) {
|
||||
"foo" -> x<!UNSAFE_CALL!>.<!>length
|
||||
"bar" -> y.length
|
||||
}
|
||||
}
|
||||
|
||||
fun test3(x: String?, y: String?) {
|
||||
when (val z = x ?: y!!) {
|
||||
"foo" -> x<!UNSAFE_CALL!>.<!>length
|
||||
"bar" -> y<!UNSAFE_CALL!>.<!>length
|
||||
"baz" -> z.length
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> id(x: T): T = x
|
||||
|
||||
fun test4(x: String?) {
|
||||
when (val y = id(x!!)) {
|
||||
"foo" -> <!DEBUG_INFO_SMARTCAST!>x<!>.length
|
||||
"bar" -> y.length
|
||||
}
|
||||
}
|
||||
|
||||
class Inv<T>(val data: T)
|
||||
|
||||
fun test5(x: Inv<out Any?>) {
|
||||
when (val y = x.data) {
|
||||
is String -> <!DEBUG_INFO_SMARTCAST!>y<!>.length // should be ok
|
||||
null -> x.data.<!UNRESOLVED_REFERENCE!>length<!> // should be error
|
||||
}
|
||||
}
|
||||
|
||||
fun test6(x: Inv<out String?>) {
|
||||
when (val <!UNUSED_VARIABLE!>y<!> = x.data) {
|
||||
is String -> <!DEBUG_INFO_SMARTCAST!>x.data<!>.length // should be ok
|
||||
}
|
||||
}
|
||||
+16
-2
@@ -1,4 +1,18 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ s1: kotlin.String, /*1*/ s2: kotlin.String): kotlin.String
|
||||
public fun test(/*0*/ x: kotlin.Any?): kotlin.String
|
||||
public fun foo(/*0*/ s1: kotlin.Int, /*1*/ s2: kotlin.Int): kotlin.Int
|
||||
public fun </*0*/ T> id(/*0*/ x: T): T
|
||||
public fun test1(/*0*/ x: kotlin.String?): kotlin.Int
|
||||
public fun test2(/*0*/ x: kotlin.String?): kotlin.Unit
|
||||
public fun test3(/*0*/ x: kotlin.String?, /*1*/ y: kotlin.String?): kotlin.Unit
|
||||
public fun test4(/*0*/ x: kotlin.String?): kotlin.Unit
|
||||
public fun test5(/*0*/ x: Inv<out kotlin.Any?>): kotlin.Unit
|
||||
public fun test6(/*0*/ x: Inv<out kotlin.String?>): kotlin.Unit
|
||||
|
||||
public final class Inv</*0*/ T> {
|
||||
public constructor Inv</*0*/ T>(/*0*/ data: T)
|
||||
public final val data: T
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user