[FIR] Properly support smartcasts on stable when subjects in when conditions

^KT-49860 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-11-24 17:14:21 +03:00
committed by teamcityserver
parent 20425fb458
commit 330574cab6
41 changed files with 1225 additions and 791 deletions
@@ -62,7 +62,7 @@ fun case_7(value_1: SealedClassEmpty): String = when (value_1) {
* ISSUES: KT-22996
*/
fun case_8(value: SealedClass?): String = when (value) {
is SealedChild1, !is SealedChild3?, is SealedChild3? -> ""
is SealedChild1, !is SealedChild3?, <!USELESS_IS_CHECK!>is SealedChild3?<!> -> ""
}
/*
@@ -72,5 +72,5 @@ fun case_8(value: SealedClass?): String = when (value) {
*/
fun case_9(value: SealedClass?): String = when (value) {
is SealedChild1, !is SealedChild3 -> ""
is SealedChild3? -> ""
<!USELESS_IS_CHECK!>is SealedChild3?<!> -> ""
}
@@ -14,8 +14,8 @@ fun case_1(value_1: SealedClass) = when (value_1) {
*/
fun case_2(value_1: SealedClass?): String = when (value_1) {
!is SealedChild2 -> "" // including null
is SealedChild2 -> ""
null -> "" // redundant
<!USELESS_IS_CHECK!>is SealedChild2<!> -> ""
<!SENSELESS_NULL_IN_WHEN!>null<!> -> "" // redundant
}
// TESTCASE NUMBER: 3
@@ -33,7 +33,7 @@ fun case_3(value_1: SealedClass?): String = when (value_1) {
fun case_4(value_1: SealedClass?) {
when (value_1) {
!is SealedChild2 -> {} // including null
is SealedChild2? -> {} // redundant nullable type check
<!USELESS_IS_CHECK!>is SealedChild2?<!> -> {} // redundant nullable type check
}
}
@@ -3,7 +3,7 @@
// TESTCASE NUMBER: 1
fun case_1(value_1: SealedClass): String = when (value_1) {
is SealedChild1, !is SealedChild3 -> ""
is SealedChild3 -> ""
<!USELESS_IS_CHECK!>is SealedChild3<!> -> ""
}
// TESTCASE NUMBER: 2
@@ -18,7 +18,7 @@ fun case_3(value_1: SealedClass): String = when (value_1) {
// TESTCASE NUMBER: 4
fun case_4(value_1: SealedClass): String = when (value_1) {
!is SealedChild1, is SealedChild1 -> ""
!is SealedChild1, <!USELESS_IS_CHECK!>is SealedChild1<!> -> ""
}
// TESTCASE NUMBER: 5
@@ -34,7 +34,7 @@ fun case_5(value_1: Any?): String = when (value_1) {
*/
fun case_6(value_1: Any?): String = when (value_1) {
is Boolean?, !is SealedChild3 -> "" // double nullable type check in the one branch
is SealedChild3 -> ""
<!USELESS_IS_CHECK!>is SealedChild3<!> -> ""
else -> ""
}
@@ -226,7 +226,7 @@ fun case_23(value_1: Nothing) {
// TESTCASE NUMBER: 24
fun case_24(value_1: Nothing?) = when (value_1) {
<!SENSELESS_COMPARISON!>throw Exception()<!>, <!SENSELESS_COMPARISON!><!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> ""<!> -> ""
<!SENSELESS_NULL_IN_WHEN!>null<!>, <!SENSELESS_COMPARISON!><!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> ""<!>, <!SENSELESS_COMPARISON!>throw throw throw Exception()<!> -> ""
<!SENSELESS_NULL_IN_WHEN!>null<!>, <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> <!RETURN_IN_FUNCTION_WITH_EXPRESSION_BODY!>return<!> "", throw throw throw Exception() -> ""
else -> ""
}