Minor: convert to expression body is forbidden also for nested non-exhaustive whens
This commit is contained in:
@@ -133,7 +133,7 @@ fun KtExpression.negate(): KtExpression {
|
||||
}
|
||||
|
||||
fun KtExpression.resultingWhens(): List<KtWhenExpression> = when (this) {
|
||||
is KtWhenExpression -> listOf(this)
|
||||
is KtWhenExpression -> listOf(this) + entries.map { it.expression?.resultingWhens() ?: listOf() }.flatten()
|
||||
is KtIfExpression -> (then?.resultingWhens() ?: listOf()) + (`else`?.resultingWhens() ?: listOf())
|
||||
is KtBinaryExpression -> (left?.resultingWhens() ?: listOf()) + (right?.resultingWhens() ?: listOf())
|
||||
is KtUnaryExpression -> this.baseExpression?.resultingWhens() ?: listOf()
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// IS_APPLICABLE: false
|
||||
enum class AccessMode { READ, WRITE, RW }
|
||||
fun whenExpr(mode: Boolean, access: AccessMode) {
|
||||
<caret>when (access) {
|
||||
AccessMode.READ -> when (mode) {
|
||||
true -> println("read")
|
||||
false -> println("noread")
|
||||
}
|
||||
AccessMode.WRITE -> when (mode) {
|
||||
true -> println("write")
|
||||
}
|
||||
AccessMode.RW -> when (mode) {
|
||||
true -> println("both")
|
||||
else -> println("no both")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun println(s: String) {}
|
||||
@@ -4960,6 +4960,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("whenWhenNonExhaustive.kt")
|
||||
public void testWhenWhenNonExhaustive() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToExpressionBody/whenWhenNonExhaustive.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("while.kt")
|
||||
public void testWhile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToExpressionBody/while.kt");
|
||||
|
||||
Reference in New Issue
Block a user