[FE 1.0] Report USELESS_IS_CHECK if is expression is always false

^KT-47684 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-07-09 14:03:48 +03:00
committed by teamcityserver
parent 785e2f862c
commit 7b5a5f5682
24 changed files with 283 additions and 59 deletions
@@ -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 { returns() implies (<!ERROR_IN_CONTRACT_DESCRIPTION!>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 { returns() implies (<!USELESS_IS_CHECK!><!ERROR_IN_CONTRACT_DESCRIPTION!>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 { returns() implies (this@case_5_1 !is ClassLevel1 || <!USELESS_IS_CHECK!><!ERROR_IN_CONTRACT_DESCRIPTION!>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 { returns() implies (<!USELESS_IS_CHECK!>this@case_5_1 !is ClassLevel1<!> || <!USELESS_IS_CHECK!><!ERROR_IN_CONTRACT_DESCRIPTION!>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()
}
}
}