[FIR] Implement checker for exhaustive when's in expression position
This commit is contained in:
@@ -1,16 +0,0 @@
|
||||
fun foo(x: Unit) = x
|
||||
|
||||
fun test() {
|
||||
if (false);
|
||||
if (true);
|
||||
|
||||
val x = if (false);
|
||||
foo(x)
|
||||
|
||||
val y: Unit = if (false);
|
||||
foo(y)
|
||||
|
||||
foo({if (1==1);}())
|
||||
|
||||
return if (true);
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
fun foo(x: Unit) = x
|
||||
|
||||
fun test() {
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ fun testMixedIfAndWhen() =
|
||||
else 1
|
||||
true -> if (true) 42
|
||||
else println()
|
||||
else -> if (true) println()
|
||||
else -> <!INVALID_IF_AS_EXPRESSION!>if<!> (true) println()
|
||||
}
|
||||
else println()
|
||||
|
||||
@@ -28,4 +28,4 @@ fun testWrappedExpressions() =
|
||||
}
|
||||
else {
|
||||
(((((42)) + 1)))
|
||||
}
|
||||
}
|
||||
|
||||
+29
-29
@@ -11,21 +11,21 @@ val mlist = MList()
|
||||
|
||||
fun work() {}
|
||||
|
||||
val xx1 = if (true) 42
|
||||
val xx2: Unit = if (true) 42
|
||||
val xx3 = idAny(if (true) 42)
|
||||
val xx4 = id(if (true) 42)
|
||||
val xx5 = idUnit(if (true) 42)
|
||||
val xx6 = null ?: if (true) 42
|
||||
val xx7 = "" + if (true) 42
|
||||
val xx1 = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
val xx2: Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
val xx3 = idAny(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
|
||||
val xx4 = id(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
|
||||
val xx5 = idUnit(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
|
||||
val xx6 = null ?: <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
val xx7 = "" + <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
|
||||
val wxx1 = when { true -> 42 }
|
||||
val wxx2: Unit = when { true -> 42 }
|
||||
val wxx3 = idAny(when { true -> 42 })
|
||||
val wxx4 = id(when { true -> 42 })
|
||||
val wxx5 = idUnit(when { true -> 42 })
|
||||
val wxx6 = null ?: when { true -> 42 }
|
||||
val wxx7 = "" + when { true -> 42 }
|
||||
val wxx1 = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
val wxx2: Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
val wxx3 = idAny(<!NO_ELSE_IN_WHEN!>when<!> { true -> 42 })
|
||||
val wxx4 = id(<!NO_ELSE_IN_WHEN!>when<!> { true -> 42 })
|
||||
val wxx5 = idUnit(<!NO_ELSE_IN_WHEN!>when<!> { true -> 42 })
|
||||
val wxx6 = null ?: <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
val wxx7 = "" + <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
|
||||
val fn1 = { if (true) 42 }
|
||||
val fn2 = { if (true) mlist.add() }
|
||||
@@ -41,24 +41,24 @@ val ufn4: () -> Unit = { when { true -> 42 } }
|
||||
val ufn5: () -> Unit = { when { true -> mlist.add() } }
|
||||
val ufn6: () -> Unit = { when { true -> work() } }
|
||||
|
||||
fun f1() = if (true) work()
|
||||
fun f2() = if (true) mlist.add()
|
||||
fun f3() = if (true) 42
|
||||
fun f4(): Unit = if (true) work()
|
||||
fun f5(): Unit = if (true) mlist.add()
|
||||
fun f6(): Unit = if (true) 42
|
||||
fun g1() = when { true -> work() }
|
||||
fun g2() = when { true -> mlist.add() }
|
||||
fun g3() = when { true -> 42 }
|
||||
fun g4(): Unit = when { true -> work() }
|
||||
fun g5(): Unit = when { true -> mlist.add() }
|
||||
fun g6(): Unit = when { true -> 42 }
|
||||
fun f1() = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) work()
|
||||
fun f2() = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) mlist.add()
|
||||
fun f3() = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
fun f4(): Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) work()
|
||||
fun f5(): Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) mlist.add()
|
||||
fun f6(): Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
fun g1() = <!NO_ELSE_IN_WHEN!>when<!> { true -> work() }
|
||||
fun g2() = <!NO_ELSE_IN_WHEN!>when<!> { true -> mlist.add() }
|
||||
fun g3() = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
fun g4(): Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> work() }
|
||||
fun g5(): Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> mlist.add() }
|
||||
fun g6(): Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
|
||||
|
||||
fun foo1(x: String?) {
|
||||
"" + if (true) 42
|
||||
"" + <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
|
||||
w@while (true) {
|
||||
x ?: if (true) break
|
||||
x ?: when { true -> break@w }
|
||||
x ?: <!INVALID_IF_AS_EXPRESSION!>if<!> (true) break
|
||||
x ?: <!NO_ELSE_IN_WHEN!>when<!> { true -> break@w }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@
|
||||
fun example() {
|
||||
val a = if (true) true else false
|
||||
val b = if (true) else false
|
||||
val c = if (true) true
|
||||
val c = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) true
|
||||
val d = if (true) true else;
|
||||
val e = if (true) {} else false
|
||||
val f = if (true) true else {}
|
||||
@@ -27,7 +27,7 @@ fun example() {
|
||||
}()
|
||||
|
||||
fun t(): Boolean {
|
||||
return if (true) true
|
||||
return <!INVALID_IF_AS_EXPRESSION!>if<!> (true) true
|
||||
}
|
||||
|
||||
return if (true) true else {}
|
||||
|
||||
Vendored
+2
-2
@@ -99,10 +99,10 @@ fun testImplicitCoercion() {
|
||||
else -> z--
|
||||
}
|
||||
|
||||
var iff = if (true) {
|
||||
var iff = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) {
|
||||
z = 34
|
||||
}
|
||||
val g = if (true) 4
|
||||
val g = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 4
|
||||
val h = if (false) 4 else {}
|
||||
|
||||
<!INAPPLICABLE_CANDIDATE!>bar<!>(if (true) {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ fun t1(x: Int) = when(x) {
|
||||
else -> 1
|
||||
}
|
||||
|
||||
fun t5(x: Int) = when (x) {
|
||||
fun t5(x: Int) = <!NO_ELSE_IN_WHEN!>when<!> (x) {
|
||||
is Int -> 1
|
||||
2 -> 2
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user