Introduce inspection to detect use of Unit as a standalone expression

So #KT-20631 Fixed
This commit is contained in:
Toshiaki Kameyama
2017-10-12 10:28:21 +03:00
committed by Mikhail Glukhikh
parent 5f4233e4bf
commit ef71f7707d
18 changed files with 196 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.RedundantUnitExpressionInspection
@@ -0,0 +1,4 @@
// PROBLEM: none
fun test() {
val u = <caret>Unit
}
@@ -0,0 +1,2 @@
// PROBLEM: none
fun test() = <caret>Unit
@@ -0,0 +1,7 @@
// PROBLEM: none
fun test(s: String?) {
val x: Any = if (s == null)
""
else
Unit<caret>
}
@@ -0,0 +1,3 @@
fun test() {
return <caret>Unit
}
@@ -0,0 +1,3 @@
fun test() {
return
}
@@ -0,0 +1,5 @@
fun test() {
val f: () -> Unit = {
<caret>Unit
}
}
@@ -0,0 +1,4 @@
fun test() {
val f: () -> Unit = {
}
}
@@ -0,0 +1,6 @@
fun test() {
val f: () -> Unit = {
<caret>Unit
Unit
}
}
@@ -0,0 +1,5 @@
fun test() {
val f: () -> Unit = {
Unit
}
}
@@ -0,0 +1,8 @@
fun test(s: String?) {
val x: Any = if (s == null) {
""
}
else {
<caret>Unit
}
}
@@ -0,0 +1,7 @@
fun test(s: String?) {
val x: Any = if (s == null) {
""
}
else {
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test() {
val x: List<Unit> = listOf(1, 2, 3).map {
return@map <caret>Unit
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
fun test() {
val x: List<Unit> = listOf(1, 2, 3).map {
return@map
}
}