[FIR] Check is for impossibility

^KT-58203 Fixed
^KT-62646
This commit is contained in:
Nikolay Lunyak
2024-02-29 15:39:33 +02:00
committed by Space Team
parent 92d8da621e
commit 88ff93df7f
42 changed files with 110 additions and 83 deletions
@@ -14,8 +14,8 @@
// TESTCASE NUMBER: 1
fun case_1(value_1: SealedClass) = when (value_1) {
!is SealedChild1 -> {}
!is SealedChild2 -> {}
!is SealedChild3 -> {}
<!USELESS_IS_CHECK!>!is SealedChild2<!> -> {}
<!USELESS_IS_CHECK!>!is SealedChild3<!> -> {}
}
/*
@@ -18,7 +18,7 @@ fun case_1(value_1: SealedClass): String = when (value_1) {
// TESTCASE NUMBER: 2
fun case_2(value_1: SealedClass) = when (value_1) {
!is SealedChild1, !is SealedChild2, !is SealedChild3 -> {}
!is SealedChild1, <!USELESS_IS_CHECK!>!is SealedChild2<!>, <!USELESS_IS_CHECK!>!is SealedChild3<!> -> {}
}
// TESTCASE NUMBER: 3
@@ -107,7 +107,7 @@ fun case_8(value_1: Any?) {
// TESTCASE NUMBER: 9
fun case_9(value_1: Any?) {
if (funWithReturnsFalse(value_1 is String) || funWithReturnsFalse(value_1 is Int)) {
if (funWithReturnsFalse(value_1 is String) || funWithReturnsFalse(<!USELESS_IS_CHECK!>value_1 is Int<!>)) {
} else {
println(value_1.length)
@@ -37,7 +37,7 @@ fun <T> T?.case_3(): Boolean {
// TESTCASE NUMBER: 4
inline fun <reified T : Number> T.case_4(): Boolean {
contract {
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (this is Int)<!>
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (<!USELESS_IS_CHECK!>this is Int<!>)<!>
}
return this is Int
}
@@ -70,13 +70,13 @@ class case_4 : ClassLevel3() {
class case_5<T> : ClassLevel5() {
inner class case_5_1 {
fun <K : Number?>K.case_5_1_1() {
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@case_5_1 !is ClassLevel1 && <!SENSELESS_COMPARISON!>this@case_5_1 != null<!> || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> && this@case_5_1_1 is Float)<!> }
if (!(this@case_5_1 !is ClassLevel1 && <!SENSELESS_COMPARISON!>this@case_5_1 != null<!> || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> && this is Float)) throw Exception()
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!USELESS_IS_CHECK!>this@case_5_1 !is ClassLevel1<!> && <!SENSELESS_COMPARISON!>this@case_5_1 != null<!> || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> && this@case_5_1_1 is Float)<!> }
if (!(<!USELESS_IS_CHECK!>this@case_5_1 !is ClassLevel1<!> && <!SENSELESS_COMPARISON!>this@case_5_1 != null<!> || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> && this is Float)) throw Exception()
}
fun case_5_1_2() {
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@case_5_1 !is ClassLevel1 || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> || <!SENSELESS_COMPARISON!>this@case_5_1 == null<!>)<!> }
if (!(this@case_5_1 !is ClassLevel1 || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> || <!SENSELESS_COMPARISON!>this@case_5_1 == null<!>)) throw Exception()
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!USELESS_IS_CHECK!>this@case_5_1 !is ClassLevel1<!> || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> || <!SENSELESS_COMPARISON!>this@case_5_1 == null<!>)<!> }
if (!(<!USELESS_IS_CHECK!>this@case_5_1 !is ClassLevel1<!> || <!USELESS_IS_CHECK!>this@case_5 is ClassLevel1<!> || <!SENSELESS_COMPARISON!>this@case_5_1 == null<!>)) throw Exception()
}
}
}
@@ -12,7 +12,7 @@
// TESTCASE NUMBER: 1
fun <T : List<T>> Inv<out T>.case_1() {
if (this is MutableList<*>) {
if (<!USELESS_IS_CHECK!>this is MutableList<*><!>) {
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out T> & kotlin.collections.MutableList<*> & Inv<out T>")!>this<!>
<!DEBUG_INFO_EXPRESSION_TYPE("Inv<out T> & kotlin.collections.MutableList<*> & Inv<out T>")!>this<!>[0] = <!ARGUMENT_TYPE_MISMATCH!><!DEBUG_INFO_EXPRESSION_TYPE("Inv<out T> & kotlin.collections.MutableList<*> & Inv<out T>")!>this<!>[1]<!>
}