[FE 1.0] Report NON_EXHAUSTIVE_WHEN_STATEMENT/NO_ELSE_IN_WHEN for when's on logical types

^KT-47709 In Progress
This commit is contained in:
Dmitriy Novozhilov
2021-07-13 12:29:54 +03:00
committed by teamcityserver
parent 85c7f386eb
commit ef635f6a96
35 changed files with 930 additions and 44 deletions
@@ -70,11 +70,11 @@ fun case_5(value_1: Int, value_2: Int, value_3: Boolean?) {
false -> "2"
null -> "3"
}
value_1 == 5 -> when (value_3) {
value_1 == 5 -> <!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_3) {
true -> "1"
false -> "2"
}
value_1 == 6 -> when (value_3) {}
value_1 == 6 -> <!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_3) {}
}
}
@@ -61,21 +61,21 @@ fun case_5(value_1: Int, value_2: Int, value_3: Boolean?) {
value_2 > 100 -> "2"
else -> "3"
}
2 -> when (value_3) {
2 -> <!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_3) {
value_2 > 1000 -> "1"
value_2 > 100 -> "2"
}
3 -> when (value_3) {}
3 -> <!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_3) {}
4 -> when (value_3) {
true -> "1"
false -> "2"
null -> "3"
}
5 -> when (value_3) {
5 -> <!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_3) {
true -> "1"
false -> "2"
}
6 -> when (value_3) {}
6 -> <!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_3) {}
}
}
@@ -41,7 +41,7 @@ fun case_3(value_1: SealedClass?): String = when (value_1) {
* ISSUES: KT-22996
*/
fun case_4(value_1: SealedClass?) {
when (value_1) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_1) {
!is SealedChild2 -> {} // including null
<!USELESS_IS_CHECK!>is SealedChild2?<!> -> {} // redundant nullable type check
}
@@ -33,7 +33,7 @@ fun case_2(value_1: Number, value_2: Int) {
// TESTCASE NUMBER: 3
fun case_3(value_1: Boolean, value_2: Boolean, value_3: Long) {
when (value_1) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_1) {
value_2 -> {}
!value_2 -> {}
getBoolean() && value_2 -> {}
@@ -27,7 +27,7 @@ fun case_2(value_1: Number, value_2: Int) {
// TESTCASE NUMBER: 3
fun case_3(value_1: Boolean, value_2: Boolean, value_3: Long) {
when (value_1) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_1) {
value_2, !value_2, getBoolean() && value_2, getChar() != 'a' -> {}
getList() === getAny(), value_3 <= 11 -> {}
}
@@ -15,7 +15,7 @@
fun case_1(value_1: EnumClass?) {
val value_2: Int
<!NON_EXHAUSTIVE_WHEN!>when<!> (value_1) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_1) {
EnumClass.NORTH -> funWithExactlyOnceCallsInPlace { value_2 = 1 }
EnumClass.SOUTH -> funWithExactlyOnceCallsInPlace { value_2 = 2 }
EnumClass.EAST -> funWithExactlyOnceCallsInPlace { value_2 = 4 }
@@ -109,7 +109,7 @@ fun case_4(value_1: Number, value_2: (() -> Unit)?) {
// TESTCASE NUMBER: 5
fun case_5(value_1: Number?, value_2: String?) {
when (value_2.case_5(value_1)) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_2.case_5(value_1)) {
true -> {
println(value_2<!UNSAFE_CALL!>.<!>length)
println(value_1<!UNSAFE_CALL!>.<!>toByte())
@@ -114,7 +114,7 @@ fun case_4(value_1: Number, value_2: (() -> Unit)?) {
* ISSUES: KT-26612
*/
fun case_5(value_1: Number?, value_2: String?) {
when (value_2.case_5(value_1)) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (value_2.case_5(value_1)) {
true -> {
println(value_2<!UNSAFE_CALL!>.<!>length)
println(<!DEBUG_INFO_SMARTCAST!>value_1<!>.toByte())
@@ -146,7 +146,7 @@ fun case_7() {
var b = a
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.String")!>b<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any & kotlin.String"), DEBUG_INFO_SMARTCAST!>b<!>.length
when (true) {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!> (true) {
true -> b = a
}