Add multilevel sections support and corresponding renaming

This commit is contained in:
victor.petukhov
2018-09-24 23:27:06 +03:00
parent 2c313e12e5
commit 84dc28374c
140 changed files with 946 additions and 943 deletions
@@ -1,7 +1,7 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [1] When expression without bound value (the form where the expression enclosed in parantheses is absent) evaluates one of the many different expressions based on corresponding conditions present in the same when entry.
NUMBER: 1
@@ -9,10 +9,10 @@
*/
// CASE DESCRIPTION: 'When' with break expression (without label).
fun case_1(value: Int): String {
fun case_1(value_1: Int): String {
while (true) {
when {
value == 1 -> <!BREAK_OR_CONTINUE_IN_WHEN!>break<!>
value_1 == 1 -> <!BREAK_OR_CONTINUE_IN_WHEN!>break<!>
}
}
@@ -20,10 +20,10 @@ fun case_1(value: Int): String {
}
// CASE DESCRIPTION: 'When' with continue expression (without label).
fun case_2(value: Int): String {
fun case_2(value_1: Int): String {
while (true) {
when {
value == 1 -> <!BREAK_OR_CONTINUE_IN_WHEN!>continue<!>
value_1 == 1 -> <!BREAK_OR_CONTINUE_IN_WHEN!>continue<!>
}
}
@@ -3,20 +3,20 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [2] Each entry consists of a boolean condition (or a special else condition), each of which is checked and evaluated in order of appearance.
NUMBER: 1
DESCRIPTION: 'When' without bound value and with not boolean condition in 'when condition'.
*/
fun case_1(value1: Int, value2: String, value3: _BasicTypesProvider): String {
fun case_1(value_1: Int, value_2: String, value_3: _BasicTypesProvider): String {
when {
<!TYPE_MISMATCH!>.012f / value1<!> -> return ""
<!TYPE_MISMATCH!>"$value2..."<!> -> return ""
<!TYPE_MISMATCH!>.012f / value_1<!> -> return ""
<!TYPE_MISMATCH!>"$value_2..."<!> -> return ""
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>'-'<!> -> return ""
<!TYPE_MISMATCH!>{}<!> -> return ""
<!TYPE_MISMATCH!>value3.getAny()<!> -> return ""
<!TYPE_MISMATCH!>value_3.getAny()<!> -> return ""
<!TYPE_MISMATCH!>-10..-1<!> -> return ""
}
@@ -3,18 +3,18 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [2] Each entry consists of a boolean condition (or a special else condition), each of which is checked and evaluated in order of appearance.
NUMBER: 2
DESCRIPTION: 'When' without bound value and not allowed comma in when entry.
*/
fun case_1(value1: _BasicTypesProvider) {
fun case_1(value_1: _BasicTypesProvider) {
when {
getBoolean()<!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> value1.getBoolean() -> return
value1.getBoolean() && getBoolean()<!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> getLong() == 1000L -> return
<!TYPE_MISMATCH!>value1.getList()<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> <!TYPE_MISMATCH!>getLong()<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> <!TYPE_MISMATCH!>{}<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> <!TYPE_MISMATCH!>Any()<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> throw Exception() -> return
getBoolean()<!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> value_1.getBoolean() -> return
value_1.getBoolean() && getBoolean()<!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> getLong() == 1000L -> return
<!TYPE_MISMATCH!>value_1.getList()<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> <!TYPE_MISMATCH!>getLong()<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> <!TYPE_MISMATCH!>{}<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> <!TYPE_MISMATCH!>Any()<!><!COMMA_IN_WHEN_CONDITION_WITHOUT_ARGUMENT!>,<!> throw Exception() -> return
}
<!UNREACHABLE_CODE!>return<!>
@@ -6,7 +6,7 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [1] When expression without bound value (the form where the expression enclosed in parantheses is absent) evaluates one of the many different expressions based on corresponding conditions present in the same when entry.
NUMBER: 1
@@ -14,80 +14,80 @@
*/
// CASE DESCRIPTION: 'When' with control structure body as literals.
fun case_1(value: Int) {
fun case_1(value_1: Int) {
when {
value == 1 -> true
value == 2 -> 100
value == 3 -> -.09f
value == 4 -> '.'
value == 5 -> "..."
value == 6 -> null
value_1 == 1 -> true
value_1 == 2 -> 100
value_1 == 3 -> -.09f
value_1 == 4 -> '.'
value_1 == 5 -> "..."
value_1 == 6 -> null
}
}
// CASE DESCRIPTION: 'When' with control structure body as arithmetic expressions.
fun case_2(value: Int, value1: Byte, value2: _BasicTypesProvider) {
fun case_2(value_1: Int, value_2: Byte, value_3: _BasicTypesProvider) {
when {
value == 1 -> -.09 % 10L
value == 3 -> value1 / -5
value == 2 -> value2.getChar(99) - 11 + 90
value_1 == 1 -> -.09 % 10L
value_1 == 3 -> value_2 / -5
value_1 == 2 -> value_3.getChar(99) - 11 + 90
}
}
// CASE DESCRIPTION: 'When' with control structure body as boolean expressions (logical, equality and comparison).
fun case_3(value: Int, value1: Boolean, value2: Long) {
fun case_3(value_1: Int, value_2: Boolean, value_3: Long) {
when {
value == 1 -> value1
value == 2 -> !value1
value == 3 -> getBoolean() && value1
value == 5 -> getChar(10) != 'a'
value == 6 -> getList() === getAny()
value == 7 -> value2 <= 11
value_1 == 1 -> value_2
value_1 == 2 -> !value_2
value_1 == 3 -> getBoolean() && value_2
value_1 == 5 -> getChar(10) != 'a'
value_1 == 6 -> getList() === getAny()
value_1 == 7 -> value_3 <= 11
}
}
// CASE DESCRIPTION: 'When' with control structure body as concatenations.
fun case_4(value: Int, value1: String, value2: String) {
fun case_4(value_1: Int, value_2: String, value_3: String) {
when {
value == 1 -> "..." + value1 + "" + "$value2" + "..."
value == 2 -> value1 + getString()
value_1 == 1 -> "..." + value_2 + "" + "$value_3" + "..."
value_1 == 2 -> value_2 + getString()
}
}
// CASE DESCRIPTION: 'When' with control structure body as when expression.
fun case_5(value: Int, value1: Int, value2: Boolean?) {
fun case_5(value_1: Int, value_2: Int, value_3: Boolean?) {
when {
value == 1 -> when {
value1 > 1000 -> "1"
value1 > 100 -> "2"
value_1 == 1 -> when {
value_2 > 1000 -> "1"
value_2 > 100 -> "2"
else -> "3"
}
value == 2 -> when {
value1 > 1000 -> "1"
value1 > 100 -> "2"
value_1 == 2 -> when {
value_2 > 1000 -> "1"
value_2 > 100 -> "2"
}
value == 3 -> when {}
value == 4 -> when (value2) {
value_1 == 3 -> when {}
value_1 == 4 -> when (value_3) {
true -> "1"
false -> "2"
null -> "3"
}
value == 5 -> when (value2) {
value_1 == 5 -> when (value_3) {
true -> "1"
false -> "2"
}
value == 6 -> when (value2) {}
value_1 == 6 -> when (value_3) {}
}
}
// CASE DESCRIPTION: 'When' as expression with control structure body as when expression (must be exhaustive).
fun case_6(value: Int, value1: Int, value2: Boolean?) = when {
value == 1 -> when {
value1 > 1000 -> 1
value1 > 100 -> 2
fun case_6(value_1: Int, value_2: Int, value_3: Boolean?) = when {
value_1 == 1 -> when {
value_2 > 1000 -> 1
value_2 > 100 -> 2
else -> 3
}
else -> when (value2) {
else -> when (value_3) {
true -> 1
false -> 2
null -> 3
@@ -95,138 +95,138 @@ fun case_6(value: Int, value1: Int, value2: Boolean?) = when {
}
// CASE DESCRIPTION: 'When' with control structure body as if expression.
fun case_7(value: Int, value1: Int, value2: Boolean?) {
fun case_7(value_1: Int, value_2: Int, value_3: Boolean?) {
when {
value == 1 -> if (value1 > 1000) "1"
value == 2 -> if (value1 > 1000) "1"
value_1 == 1 -> if (value_2 > 1000) "1"
value_1 == 2 -> if (value_2 > 1000) "1"
else "2"
value == 3 -> if (value1 < 100) "1"
else if (value1 < 10) "2"
value_1 == 3 -> if (value_2 < 100) "1"
else if (value_2 < 10) "2"
else "4"
value == 4 -> if (value2 == null) "1"
else if (value2) "2"
else if (!value2) "3"
value_1 == 4 -> if (value_3 == null) "1"
else if (value_3) "2"
else if (!value_3) "3"
}
}
// CASE DESCRIPTION: 'When' as expression with control structure body as if expression (must be exhaustive).
fun case_8(value: Int, value1: Int) = when {
value == 1 -> if (value1 > 1000) "1"
fun case_8(value_1: Int, value_2: Int) = when {
value_1 == 1 -> if (value_2 > 1000) "1"
else "2"
else -> if (value1 < 100) "1"
else if (value1 < 10) "2"
else -> if (value_2 < 100) "1"
else if (value_2 < 10) "2"
else "4"
}
// CASE DESCRIPTION: 'When' with control structure body as try expression.
fun case_9(value: Int, value1: String, value2: String) = when {
value == 1 -> <!IMPLICIT_CAST_TO_ANY!>try { 4 } catch (e: Exception) { 5 }<!>
value == 2 -> <!IMPLICIT_CAST_TO_ANY!>try { throw Exception() } catch (e: Exception) { value1 }<!>
else -> <!IMPLICIT_CAST_TO_ANY!>try { throw Exception() } catch (e: Exception) { {value2} } finally { }<!>
fun case_9(value_1: Int, value_2: String, value_3: String) = when {
value_1 == 1 -> <!IMPLICIT_CAST_TO_ANY!>try { 4 } catch (e: Exception) { 5 }<!>
value_1 == 2 -> <!IMPLICIT_CAST_TO_ANY!>try { throw Exception() } catch (e: Exception) { value_2 }<!>
else -> <!IMPLICIT_CAST_TO_ANY!>try { throw Exception() } catch (e: Exception) { {value_3} } finally { }<!>
}
// CASE DESCRIPTION: 'When' with control structure body as elvis operator expression.
fun case_10(value: Int, value1: String?, value2: String?) {
fun case_10(value_1: Int, value_2: String?, value_3: String?) {
when {
value == 1 -> value1 ?: true
value == 2 -> value1 ?: value2 ?: true
value == 3 -> value1!! <!USELESS_ELVIS!>?: true<!>
value_1 == 1 -> value_2 ?: true
value_1 == 2 -> value_2 ?: value_3 ?: true
value_1 == 3 -> value_2!! <!USELESS_ELVIS!>?: true<!>
}
}
// CASE DESCRIPTION: 'When' with control structure body as range expression.
fun case_11(value: Int) {
fun case_11(value_1: Int) {
when {
value == 1 -> 1..10
value == 2 -> -100L..100L
value == 3 -> -getInt()..getLong()
value_1 == 1 -> 1..10
value_1 == 2 -> -100L..100L
value_1 == 3 -> -getInt()..getLong()
}
}
// CASE DESCRIPTION: 'When' with control structure body as cast expression.
fun case_12(value: Int, value1: Collection<Int>, value2: Collection<Int>?) {
fun case_12(value_1: Int, value_2: Collection<Int>, value_3: Collection<Int>?) {
when {
value == 1 -> value1 as MutableList<Int>
value == 2 -> value1 as? MutableList<Int>
value == 3 -> value2 <!UNCHECKED_CAST!>as? MutableMap<Int, Int><!>
value == 4 -> (value1 <!UNCHECKED_CAST!>as? Map<Int, Int><!>) as MutableMap<Int, Int>
value_1 == 1 -> value_2 as MutableList<Int>
value_1 == 2 -> value_2 as? MutableList<Int>
value_1 == 3 -> value_3 <!UNCHECKED_CAST!>as? MutableMap<Int, Int><!>
value_1 == 4 -> (value_2 <!UNCHECKED_CAST!>as? Map<Int, Int><!>) as MutableMap<Int, Int>
}
}
// CASE DESCRIPTION: 'When' with control structure body as prefix operator expression.
fun case_13(value: Int, value1: Int, value2: Int, value3: Boolean) {
var mutableValue1 = value1
var mutableValue2 = value2
fun case_13(value_1: Int, value_2: Int, value_3: Int, value_4: Boolean) {
var mutablevalue_2 = value_2
var mutablevalue_3 = value_3
when {
value == 1 -> ++mutableValue1
value == 2 -> --mutableValue2
value == 3 -> !value3
value_1 == 1 -> ++mutablevalue_2
value_1 == 2 -> --mutablevalue_3
value_1 == 3 -> !value_4
}
}
// CASE DESCRIPTION: 'When' with control structure body as postfix operator expression.
fun case_14(value: Int, value1: Int, value2: Int, value3: Boolean?) {
var mutableValue1 = value1
var mutableValue2 = value2
fun case_14(value_1: Int, value_2: Int, value_3: Int, value_4: Boolean?) {
var mutablevalue_2 = value_2
var mutablevalue_3 = value_3
when {
value == 1 -> <!UNUSED_CHANGED_VALUE!>mutableValue1++<!>
value == 2 -> <!UNUSED_CHANGED_VALUE!>mutableValue2--<!>
value == 3 -> value3!!
value_1 == 1 -> <!UNUSED_CHANGED_VALUE!>mutablevalue_2++<!>
value_1 == 2 -> <!UNUSED_CHANGED_VALUE!>mutablevalue_3--<!>
value_1 == 3 -> value_4!!
}
}
// CASE DESCRIPTION: 'When' with control structure body as indexing expression.
fun case_15(value: Int, value1: List<Int>, value2: List<List<List<List<Int>>>>) {
fun case_15(value_1: Int, value_2: List<Int>, value_3: List<List<List<List<Int>>>>) {
when {
value == 1 -> value1[0]
value == 2 -> value2[0][-4][1][-1]
value_1 == 1 -> value_2[0]
value_1 == 2 -> value_3[0][-4][1][-1]
}
}
// CASE DESCRIPTION: 'When' with control structure body as call expression.
fun case_16(value: Int, value1: _Class, value2: _Class?, value3: Int) {
fun case_16(value_1: Int, value_2: _Class, value_3: _Class?, value_4: Int) {
fun __fun_1(): () -> Unit { return fun() { } }
when {
value == 1 -> _funWithoutArgs()
value == 2 -> __fun_1()()
value == 3 -> value1.fun_2(value3)
value == 4 -> value2?.fun_2(value3)
value == 5 -> value2!!.fun_2(value3)
value_1 == 1 -> _funWithoutArgs()
value_1 == 2 -> __fun_1()()
value_1 == 3 -> value_2.fun_2(value_4)
value_1 == 4 -> value_3?.fun_2(value_4)
value_1 == 5 -> value_3!!.fun_2(value_4)
}
}
// CASE DESCRIPTION: 'When' with control structure body as property access expression.
fun case_17(value: Int, value1: _Class, value2: _Class?) {
fun case_17(value_1: Int, value_2: _Class, value_3: _Class?) {
when {
value == 1 -> value1.prop_1
value == 2 -> value2?.prop_1
value == 3 -> value1::prop_1.get()
value == 4 -> value2!!::prop_3.get()
value_1 == 1 -> value_2.prop_1
value_1 == 2 -> value_3?.prop_1
value_1 == 3 -> value_2::prop_1.get()
value_1 == 4 -> value_3!!::prop_3.get()
}
}
// CASE DESCRIPTION: 'When' with control structure body as fun literal.
fun case_18(value: Int) {
fun case_18(value_1: Int) {
val fun_1 = fun(): Int { return 0 }
when {
value == 1 -> fun() {}
value == 2 -> fun(): Int { return 0 }
value == 3 -> fun(): () -> Unit { return fun() {} }
value == 4 -> fun_1
value_1 == 1 -> fun() {}
value_1 == 2 -> fun(): Int { return 0 }
value_1 == 3 -> fun(): () -> Unit { return fun() {} }
value_1 == 4 -> fun_1
}
}
// CASE DESCRIPTION: 'When' with control structure body as lambda literal.
fun case_19(value: Int): () -> Any {
fun case_19(value_1: Int): () -> Any {
val lambda_1 = { 0 }
return when {
value == 1 -> lambda_1
value == 2 -> { { {} } }
value_1 == 1 -> lambda_1
value_1 == 2 -> { { {} } }
else -> { -> (Int)
{ arg: Int -> { { println(arg) } } }
}
@@ -234,18 +234,18 @@ fun case_19(value: Int): () -> Any {
}
// CASE DESCRIPTION: 'When' with control structure body as object literal.
fun case_20(value: Int) {
fun case_20(value_1: Int) {
val object_1 = object {
val prop_1 = 1
}
when {
value == 1 -> object {}
value == 2 -> object {
value_1 == 1 -> object {}
value_1 == 2 -> object {
private fun fun_1() { }
val prop_1 = 1
}
value == 3 -> object_1
value_1 == 3 -> object_1
}
}
@@ -255,41 +255,41 @@ class A {
val lambda_1 = { 1 }
fun fun_1(): Int { return 1 }
fun case_21(value: Int) {
fun case_21(value_1: Int) {
when {
value == 1 -> this
value == 2 -> ((this))
value == 3 -> this::prop_1.get()
value == 4 -> this.prop_1
value == 5 -> this.lambda_1()
value == 6 -> this::lambda_1.get()()
value == 7 -> this.fun_1()
value == 8 -> this::fun_1.invoke()
value_1 == 1 -> this
value_1 == 2 -> ((this))
value_1 == 3 -> this::prop_1.get()
value_1 == 4 -> this.prop_1
value_1 == 5 -> this.lambda_1()
value_1 == 6 -> this::lambda_1.get()()
value_1 == 7 -> this.fun_1()
value_1 == 8 -> this::fun_1.invoke()
}
}
}
// CASE DESCRIPTION: 'When' with control structure body as throw expression.
fun case_22(value: Int) {
fun case_22(value_1: Int) {
when {
value == 1 -> throw Exception()
value == 2 -> throw throw throw Exception()
value_1 == 1 -> throw Exception()
value_1 == 2 -> throw throw throw Exception()
}
}
// CASE DESCRIPTION: 'When' with control structure body as return expression.
fun case_23(value: Int) {
fun case_23(value_1: Int) {
fun r_1() {
when {
value == 1 -> return
value == 2 -> <!UNREACHABLE_CODE!>return return<!> return
value_1 == 1 -> return
value_1 == 2 -> <!UNREACHABLE_CODE!>return return<!> return
}
}
fun r_2(): List<Int>? {
when {
value == 1 -> return listOf(0, 1, 2)
value == 2 -> return null
value_1 == 1 -> return listOf(0, 1, 2)
value_1 == 2 -> return null
}
return null
@@ -297,24 +297,24 @@ fun case_23(value: Int) {
}
// CASE DESCRIPTION: 'When' with control structure body as continue expression.
fun case_24(value: Int) {
fun case_24(value_1: Int) {
loop1@ while (true) {
loop2@ while (true) {
when {
value == 1 -> continue@loop1
value == 2 -> continue@loop2
value_1 == 1 -> continue@loop1
value_1 == 2 -> continue@loop2
}
}
}
}
// CASE DESCRIPTION: 'When' with control structure body as break expression.
fun case_25(value: Int) {
fun case_25(value_1: Int) {
loop1@ while (true) {
loop2@ while (true) {
when {
value == 1 -> break@loop1
value == 2 -> break@loop2
value_1 == 1 -> break@loop1
value_1 == 2 -> break@loop2
}
}
}
@@ -5,7 +5,7 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [2] Each entry consists of a boolean condition (or a special else condition), each of which is checked and evaluated in order of appearance.
NUMBER: 1
@@ -13,14 +13,14 @@
*/
// CASE DESCRIPTION: 'When' with boolean expressions and else branch.
fun case_1(value1: Boolean, value2: Long): Int {
fun case_1(value_1: Boolean, value_2: Long): Int {
return when {
value1 -> 1
getBoolean() && value1 -> 2
value_1 -> 1
getBoolean() && value_1 -> 2
getChar(10) != 'a' -> 3
getList() === getAny() -> 4
value2 <= 11 -> 5
!value1 -> 6
value_2 <= 11 -> 5
!value_1 -> 6
else -> 7
}
}
@@ -29,12 +29,12 @@ fun case_1(value1: Boolean, value2: Long): Int {
CASE DESCRIPTION: 'When' with boolean expressions.
NOTE: for potential analysys on exhaustive by enum of when without bound value.
*/
fun case_2(value: _EnumClass) {
fun case_2(value_1: _EnumClass) {
when {
value == _EnumClass.NORTH -> {}
value == _EnumClass.SOUTH -> {}
value == _EnumClass.WEST -> {}
value == _EnumClass.EAST -> {}
value_1 == _EnumClass.NORTH -> {}
value_1 == _EnumClass.SOUTH -> {}
value_1 == _EnumClass.WEST -> {}
value_1 == _EnumClass.EAST -> {}
}
}
@@ -42,10 +42,10 @@ fun case_2(value: _EnumClass) {
CASE DESCRIPTION: 'When' with boolean expressions.
NOTE: for potential analysys on exhaustive by boolean of when without bound value.
*/
fun case_3(value: Boolean) {
fun case_3(value_1: Boolean) {
when {
value == true -> return
value == false -> return
value_1 == true -> return
value_1 == false -> return
}
}
@@ -53,11 +53,11 @@ fun case_3(value: Boolean) {
CASE DESCRIPTION: 'When' with boolean literals.
NOTE: for potential mark code after true branch as unreacable.
*/
fun case_4(value1: Boolean) {
fun case_4(value_1: Boolean) {
when {
false -> return
true -> return
value1 -> return
value_1 -> return
}
}
@@ -65,60 +65,60 @@ fun case_4(value1: Boolean) {
CASE DESCRIPTION: 'When' with boolean constants.
NOTE: for potential const propagation use in this case.
*/
fun case_5(value1: Boolean) {
val value2 = false
val value3 = false || !!!false || false
fun case_5(value_1: Boolean) {
val value_2 = false
val value_3 = false || !!!false || false
when {
value3 -> return
value2 -> return
value1 -> return
value_3 -> return
value_2 -> return
value_1 -> return
}
}
// CASE DESCRIPTION: 'When' with type checking operator.
fun case_6(value: Any) {
fun case_6(value_1: Any) {
when {
value is Nothing -> {}
value is Int -> {}
value is Boolean -> {}
value is String -> {}
value is Number -> {}
value is Float -> {}
<!USELESS_IS_CHECK!>value is Any<!> -> {}
value_1 is Nothing -> {}
value_1 is Int -> {}
value_1 is Boolean -> {}
value_1 is String -> {}
value_1 is Number -> {}
value_1 is Float -> {}
<!USELESS_IS_CHECK!>value_1 is Any<!> -> {}
}
}
/*
CASE DESCRIPTION: 'When' with invert type checking operator.
NOTE: for potential analysys on exhaustive of when without bound value.
NOTE: for potential analysys on exhaustive of when without bound value_1.
*/
fun case_7(value: Any) {
fun case_7(value_1: Any) {
when {
value !is Number -> {}
value is Float -> {}
<!USELESS_IS_CHECK!>value is Number<!> -> {}
<!USELESS_IS_CHECK!>value is Any<!> -> {}
value_1 !is Number -> {}
value_1 is Float -> {}
<!USELESS_IS_CHECK!>value_1 is Number<!> -> {}
<!USELESS_IS_CHECK!>value_1 is Any<!> -> {}
}
}
/*
CASE DESCRIPTION: 'When' with type checking operator by sealed class.
NOTE: for potential analysys on exhaustive by sealed class of when without bound value.
NOTE: for potential analysys on exhaustive by sealed class of when without bound value_1.
*/
fun case_8(value: _SealedClass) {
fun case_8(value_1: _SealedClass) {
when {
value is _SealedChild1 -> {}
value is _SealedChild2 -> {}
value is _SealedChild3 -> {}
value_1 is _SealedChild1 -> {}
value_1 is _SealedChild2 -> {}
value_1 is _SealedChild3 -> {}
}
}
// CASE DESCRIPTION: 'When' with containment operator.
fun case_9(value: Int, value1: IntRange) {
fun case_9(value_1: Int, value_2: IntRange) {
when {
value in -10..100L -> {}
value in value1 -> {}
value !in listOf(0, 1, 2) -> {}
value_1 in -10..100L -> {}
value_1 in value_2 -> {}
value_1 !in listOf(0, 1, 2) -> {}
}
}
@@ -1,7 +1,7 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [2] Each entry consists of a boolean condition (or a special else condition), each of which is checked and evaluated in order of appearance.
NUMBER: 2
@@ -3,17 +3,17 @@
/*
KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
SECTION: when-expression
SECTIONS: when-expression
PARAGRAPH: 3
SENTENCE: [2] Each entry consists of a boolean condition (or a special else condition), each of which is checked and evaluated in order of appearance.
NUMBER: 3
DESCRIPTION: 'When' without bound value and with Nothing in condition (subtype of Boolean).
UNEXPECTED BEHAVIOUR
DISCUSSION
ISSUES: KT-25948
*/
// CASE DESCRIPTION: 'When' with return expression in condition.
fun case_1(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider) {
fun case_1(<!UNUSED_PARAMETER!>value_1<!>: _BasicTypesProvider) {
when {
return -> <!UNREACHABLE_CODE!>return<!>
<!UNREACHABLE_CODE!>return == return -> return<!>
@@ -24,7 +24,7 @@ fun case_1(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider) {
}
// CASE DESCRIPTION: 'When' with throw expression in condition.
fun case_2(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider) {
fun case_2(<!UNUSED_PARAMETER!>value_1<!>: _BasicTypesProvider) {
when {
throw Exception() -> <!UNREACHABLE_CODE!>return<!>
<!UNREACHABLE_CODE!>(throw Exception()) == (throw Exception()) -> return<!>
@@ -35,7 +35,7 @@ fun case_2(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider) {
}
// CASE DESCRIPTION: 'When' with break expression in condition.
fun case_3(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider) {
fun case_3(<!UNUSED_PARAMETER!>value_1<!>: _BasicTypesProvider) {
loop1@ while (true) {
loop2@ while (true) {
loop3@ while (true) {
@@ -50,7 +50,7 @@ fun case_3(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider) {
}
// CASE DESCRIPTION: 'When' with continue expression in condition.
fun case_4(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider): String {
fun case_4(<!UNUSED_PARAMETER!>value_1<!>: _BasicTypesProvider): String {
loop1@ while (true) {
loop2@ while (true) {
loop3@ while (true) {
@@ -65,19 +65,19 @@ fun case_4(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider): String {
}
// CASE DESCRIPTION: 'When' with values of Nothing type.
fun case_6(value1: Nothing, <!UNUSED_PARAMETER!>value2<!>: _BasicTypesProvider): String {
fun case_6(value_1: Nothing, <!UNUSED_PARAMETER!>value_2<!>: _BasicTypesProvider): String {
when {
value1 -> <!UNREACHABLE_CODE!>return ""<!>
<!UNREACHABLE_CODE!>value2.getNothing() -> return ""<!>
value_1 -> <!UNREACHABLE_CODE!>return ""<!>
<!UNREACHABLE_CODE!>value_2.getNothing() -> return ""<!>
<!UNREACHABLE_CODE!>getNothing() -> return ""<!>
<!UNREACHABLE_CODE!>value1 && (getNothing() == value2.getNothing()) -> return ""<!>
<!UNREACHABLE_CODE!>value_1 && (getNothing() == value_2.getNothing()) -> return ""<!>
}
<!UNREACHABLE_CODE!>return ""<!>
}
// CASE DESCRIPTION: 'When' with mixed Nothing expression in condition.
fun case_5(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider, <!UNUSED_PARAMETER!>value2<!>: Nothing) {
fun case_5(<!UNUSED_PARAMETER!>value_1<!>: _BasicTypesProvider, <!UNUSED_PARAMETER!>value_2<!>: Nothing) {
loop1@ while (true) {
loop2@ while (true) {
loop3@ while (true) {
@@ -87,9 +87,9 @@ fun case_5(<!UNUSED_PARAMETER!>value1<!>: _BasicTypesProvider, <!UNUSED_PARAMETE
<!UNREACHABLE_CODE!>continue@loop1 != 10L && (return return) == continue@loop1 -> return<!>
<!UNREACHABLE_CODE!>return continue@loop1 -> return<!>
<!UNREACHABLE_CODE!>(throw break@loop1) && break@loop3 -> return<!>
<!UNREACHABLE_CODE!>(throw getNothing()) && value1.getNothing() -> return<!>
<!UNREACHABLE_CODE!>return return return value2 -> return<!>
<!UNREACHABLE_CODE!>getNothing() != 10L && (return return) == value2 -> return<!>
<!UNREACHABLE_CODE!>(throw getNothing()) && value_1.getNothing() -> return<!>
<!UNREACHABLE_CODE!>return return return value_2 -> return<!>
<!UNREACHABLE_CODE!>getNothing() != 10L && (return return) == value_2 -> return<!>
}
}
}