FIR checker: warn useless as and is

This commit is contained in:
Jinseong Jeon
2021-04-28 22:32:51 -07:00
committed by TeamCityServer
parent 19d939c36e
commit e2dc21da90
141 changed files with 417 additions and 543 deletions
@@ -37,4 +37,4 @@ fun case4() {
x checkType { check<Boolean>() }
}
class A
class A
@@ -1,83 +0,0 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-435
* MAIN LINK: expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 9
* NUMBER: 1
* DESCRIPTION: Non-exhaustive when using subclasses of the sealed class.
* HELPERS: sealedClasses
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: SealedClass): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
is SealedChild1 -> ""
is SealedChild2 -> ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: SealedClass): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
is SealedChild1, is SealedChild2 -> ""
}
// TESTCASE NUMBER: 3
fun case_3(value_1: SealedClassMixed): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
is SealedMixedChild1 -> ""
is SealedMixedChild2 -> ""
SealedMixedChildObject1 -> ""
}
// TESTCASE NUMBER: 4
fun case_4(value_1: SealedClassMixed): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
SealedMixedChildObject1, is SealedMixedChild2, is SealedMixedChild1 -> ""
}
// TESTCASE NUMBER: 5
fun case_5(value_1: SealedClassMixed): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
is SealedMixedChild1 -> ""
is SealedMixedChild2 -> ""
is SealedMixedChild3 -> ""
}
// TESTCASE NUMBER: 6
fun case_6(value_1: SealedClassMixed): Int = <!NO_ELSE_IN_WHEN!>when<!>(value_1) { }
// TESTCASE NUMBER: 7
fun case_7(value_1: SealedClassSingleWithObject): Int = <!NO_ELSE_IN_WHEN!>when<!>(value_1) { }
// TESTCASE NUMBER: 8
fun case_8(value_1: SealedClassEmpty): String = <!NO_ELSE_IN_WHEN!>when<!> (value_1) { }
// TESTCASE NUMBER: 9
fun case_9(value_1: Number): String = <!NO_ELSE_IN_WHEN!>when<!> (value_1) {
is Byte -> ""
is Double -> ""
is Float -> ""
is Int -> ""
is Long -> ""
is Short -> ""
}
/*
* TESTCASE NUMBER: 10
* DISCUSSION: maybe make exhaustive without else?
*/
fun case_10(value_1: Any): String = <!NO_ELSE_IN_WHEN!>when<!> (value_1) {
is Any -> ""
}
// TESTCASE NUMBER: 11
fun case_11(value_1: SealedClass): String = <!NO_ELSE_IN_WHEN!>when<!> {
value_1 is SealedChild1 -> ""
value_1 is SealedChild2 -> ""
value_1 is SealedChild3 -> ""
}
// TESTCASE NUMBER: 12
fun case_12(value_1: SealedClassMixed): String = <!NO_ELSE_IN_WHEN!>when<!>(value_1) {
is SealedMixedChild1 -> ""
is SealedMixedChild2 -> ""
is SealedMixedChild3 -> ""
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// SKIP_TXT
@@ -53,7 +53,7 @@ fun case_6(value_1: SealedClass?): String = when (value_1) {
// TESTCASE NUMBER: 7
fun case_7(value_1: SealedClassSingle): String = when (value_1) {
is SealedClassSingle -> ""
<!USELESS_IS_CHECK!>is SealedClassSingle<!> -> ""
else -> ""
}
@@ -11,7 +11,7 @@ fun case_1(value_1: SealedClass): Int = when (value_1) {
// TESTCASE NUMBER: 2
fun case_2(value_1: SealedClass): String = when (value_1) {
is SealedClass -> ""
<!USELESS_IS_CHECK!>is SealedClass<!> -> ""
}
// TESTCASE NUMBER: 3
@@ -73,7 +73,7 @@ fun case_6(value_1: Any) {
value_1 is String -> {}
value_1 is Number -> {}
value_1 is Float -> {}
value_1 is Any -> {}
<!USELESS_IS_CHECK!>value_1 is Any<!> -> {}
}
}
@@ -85,8 +85,8 @@ fun case_7(value_1: Any) {
when {
value_1 !is Number -> {}
value_1 is Float -> {}
value_1 is Number -> {}
value_1 is Any -> {}
<!USELESS_IS_CHECK!>value_1 is Number<!> -> {}
<!USELESS_IS_CHECK!>value_1 is Any<!> -> {}
}
}
@@ -29,7 +29,7 @@ fun case_3(value_1: Any?): String = when (value_1) {
// TESTCASE NUMBER: 4
fun case_4(value_1: Any): String = when (value_1) {
is Any? -> ""
<!USELESS_IS_CHECK!>is Any?<!> -> ""
else -> ""
}
@@ -70,7 +70,7 @@ interface A3
// TESTCASE NUMBER: 4
fun case4(x: C?) {
if (x is B4 && x is A4) {
if (x is B4 && <!USELESS_IS_CHECK!>x is A4<!>) {
x
<!DEBUG_INFO_EXPRESSION_TYPE("C? & C")!>x<!>
x.foo()