Improve: add more cases for MoveVariableDeclarationIntoWhen

#KT-30499 Fixed
This commit is contained in:
Dmitry Gridin
2019-03-21 16:32:41 +07:00
parent c84ff1d8b1
commit e11072b8c2
11 changed files with 120 additions and 1 deletions
@@ -0,0 +1,9 @@
fun test() = true
fun foo(): Int {
val a<caret> = test()
return when (a) {
true -> 42
else -> null
} ?: 55
}
@@ -0,0 +1,8 @@
fun test() = true
fun foo(): Int {
return when (test()) {
true -> 42
else -> null
} ?: 55
}
@@ -0,0 +1,9 @@
fun test() = 42
fun foo() {
val a<caret> = test()
val b = when (a) {
1 -> a
else -> 24
}
}
@@ -0,0 +1,8 @@
fun test() = 42
fun foo() {
val b = when (val a = test()) {
1 -> a
else -> 24
}
}
@@ -0,0 +1,9 @@
fun test() = 42
fun foo(): Int {
val a<caret> = test()
return when (a) {
1 -> a
else -> 24
}
}
@@ -0,0 +1,8 @@
fun test() = 42
fun foo(): Int {
return when (val a = test()) {
1 -> a
else -> 24
}
}
@@ -0,0 +1,9 @@
fun test() = true
fun foo() {
val a<caret> = test()
val b = !when (a) {
true -> true
else -> false
}
}
@@ -0,0 +1,8 @@
fun test() = true
fun foo() {
val b = !when (test()) {
true -> true
else -> false
}
}
@@ -0,0 +1,10 @@
// PROBLEM: none
fun test() = true
fun foo(): Int {
val a<caret> = test()
return null ?: when (a) {
true -> 42
else -> 5
}
}