diff --git a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.fir.kt deleted file mode 100644 index 7ddc8f0f5a1..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.fir.kt +++ /dev/null @@ -1,19 +0,0 @@ -// !LANGUAGE: +NewInference -// !DIAGNOSTICS: -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION -// SKIP_TXT - -// TESTCASE NUMBER: 1 - -fun case1() { - val b = true - val a = if (b) { - "true" - } -} - -// TESTCASE NUMBER: 2 - -fun case2() { - val b = true - val a = if (b) "true" -} diff --git a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.kt index d44f58871e0..6f05ffc27e6 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !LANGUAGE: +NewInference // !DIAGNOSTICS: -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION // SKIP_TXT diff --git a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.2.fir.kt index 775c449d4a2..e29d0112510 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.2.fir.kt @@ -2,6 +2,15 @@ // !DIAGNOSTICS: -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION // SKIP_TXT +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-296 + * MAIN LINK: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 1 + * NUMBER: 2 + * DESCRIPTION: check if-expressions must have both branches. + */ + // TESTCASE NUMBER: 1 fun case1() { @@ -9,7 +18,7 @@ fun case1() { val c = true val a = if (b) { "first true" - } else if (c) { + } else if (c) { "else if true" } } diff --git a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.3.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.3.fir.kt index 1767cf6d9e7..5f9a0c36a00 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.3.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/1.3.fir.kt @@ -2,6 +2,15 @@ // !DIAGNOSTICS: -UNREACHABLE_CODE -IMPLICIT_CAST_TO_ANY -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION // SKIP_TXT +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-296 + * MAIN LINK: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 1 + * NUMBER: 3 + * DESCRIPTION: check if-expressions must have both branches. (attempt to pass Nothing to if-condition without 'else' key word) + */ + fun throwExc(b: Boolean): Boolean { if (b) throw Exception() else return false @@ -9,13 +18,13 @@ fun throwExc(b: Boolean): Boolean { // TESTCASE NUMBER: 1 fun case1() { - val x1 = if (throwExc(false)) true + val x1 = if (throwExc(false)) true } // TESTCASE NUMBER: 3 fun case3() { - val x1 = if (throwExc(true)) true + val x1 = if (throwExc(true)) true } /* @@ -24,18 +33,18 @@ fun case3() { * ISSUES: KT-35510 */ fun case4() { - val x1 = if (throw Exception()) true + val x1 = if (throw Exception()) true - val x2 = if (TODO()) true + val x2 = if (TODO()) true - val x0 = if (false) true else if (throw Exception()) ; + val x0 = if (false) true else if (throw Exception()) ; } // TESTCASE NUMBER: 5 fun case5() { var flag: Boolean? = null - val x1 = if (flag ?: throw Exception()) true + val x1 = if (flag ?: throw Exception()) true } /* @@ -44,7 +53,7 @@ fun case5() { * ISSUES: KT-35510 */ fun case6() { - val k1 = if(throw Exception()); + val k1 = if(throw Exception()); } /* @@ -62,7 +71,7 @@ fun case7(nothing: Nothing) { * ISSUES: KT-35510 */ fun case8(nothing: Nothing) { - val x1 = if (nothing) true + val x1 = if (nothing) true } /* diff --git a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/2.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/2.1.fir.kt index fd3905ad21e..86ea234ab6c 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/2.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/control--and-data-flow-analysis/control-flow-graph/expressions-1/conditional-expressions/p-1/neg/2.1.fir.kt @@ -2,6 +2,16 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_PARAMETER -UNUSED_EXPRESSION // SKIP_TXT +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-296 + * MAIN LINK: control--and-data-flow-analysis, control-flow-graph, expressions-1, conditional-expressions -> paragraph 1 -> sentence 2 + * NUMBER: 1 + * DESCRIPTION: check any if-statement in kotlin may be trivially turned into such an expression by replacing the missing branch with a kotlin.Unit object expression. + * HELPERS: checkType + */ + // TESTCASE NUMBER: 1 fun case1() { @@ -9,7 +19,7 @@ fun case1() { if (!b) { println("this is statement") } - val statement = if (!b) { println("statement could not be assigned") } + val statement = if (!b) { println("statement could not be assigned") } } // TESTCASE NUMBER: 2 diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.fir.kt deleted file mode 100644 index 54f48e8883c..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.fir.kt +++ /dev/null @@ -1,16 +0,0 @@ -// SKIP_TXT - -// TESTCASE NUMBER: 1 -fun case_1(value_1: Int): String = when { - value_1 == 1 -> "" - value_1 == 2 -> "" - value_1 == 3 -> "" -} - -// TESTCASE NUMBER: 2 -fun case_2(value_1: Int): String = when { - value_1 == 1 -> "" -} - -// TESTCASE NUMBER: 3 -fun case_3(): Int = when {} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.kt index ca615536179..62f00d0c2c2 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // SKIP_TXT /* diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.fir.kt deleted file mode 100644 index bd125a9d679..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.fir.kt +++ /dev/null @@ -1,17 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -// SKIP_TXT - -// TESTCASE NUMBER: 1 -fun case_1(value_1: Int): String = when (value_1) { - 1 -> "" - 2 -> "" - 3 -> "" -} - -// TESTCASE NUMBER: 2 -fun case_2(value_1: Int): String = when (value_1) { - 1 -> "" -} - -// TESTCASE NUMBER: 3 -fun case_3(value_1: Int): Int = when (value_1) {} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.kt index 6df980a3982..2621f903616 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/1.2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION // SKIP_TXT diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.fir.kt deleted file mode 100644 index eb07a21078b..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.fir.kt +++ /dev/null @@ -1,19 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -// SKIP_TXT - - - -// TESTCASE NUMBER: 1 -fun case_1(value_1: Boolean?): String = when(value_1) { - true -> "" - false -> "" -} - -// TESTCASE NUMBER: 2 -fun case_2(value_1: Boolean?): String = when(value_1) { - true -> "" - null -> "" -} - -// TESTCASE NUMBER: 3 -fun case_3(value_1: Boolean?): Int = when(value_1) { } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.kt index 9e3a53b5d06..836b4f37b7d 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION // SKIP_TXT diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.fir.kt deleted file mode 100644 index 5f3ce02603a..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.fir.kt +++ /dev/null @@ -1,72 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -// SKIP_TXT - - -// TESTCASE NUMBER: 1 -fun case_1(value_1: SealedClass?): String = when(value_1) { - is SealedChild1 -> "" - is SealedChild2 -> "" - is SealedChild3 -> "" -} - -// TESTCASE NUMBER: 2 -fun case_2(value_1: SealedClassMixed?): String = when(value_1) { - is SealedMixedChild1 -> "" - is SealedMixedChild2 -> "" - SealedMixedChildObject1 -> "" - null -> "" -} - -// TESTCASE NUMBER: 3 -fun case_3(value_1: SealedClassMixed?): String = when(value_1) { - null, is SealedMixedChild1, is SealedMixedChild2, SealedMixedChildObject1 -> "" -} - -// TESTCASE NUMBER: 4 -fun case_4(value_1: SealedClassMixed?): String = when(value_1) { - is SealedMixedChild1 -> "" - is SealedMixedChild2 -> "" - is SealedMixedChild3 -> "" - SealedMixedChildObject1 -> "" - SealedMixedChildObject2 -> "" - SealedMixedChildObject3 -> "" -} - -// TESTCASE NUMBER: 5 -fun case_5(value_1: SealedClassMixed?): String = when(value_1) { - is SealedMixedChild1 -> "" - is SealedMixedChild2 -> "" - is SealedMixedChild3 -> "" -} - -// TESTCASE NUMBER: 6 -fun case_6(value_1: SealedClassMixed?): Int = when(value_1) {} - -// TESTCASE NUMBER: 7 -fun case_7(value_1: SealedClassMixed?): String = when(value_1) { - is SealedMixedChild1 -> "" - is SealedMixedChild2-> "" - is SealedMixedChild3 -> "" - null -> "" -} - -// TESTCASE NUMBER: 8 -fun case_8(value_1: SealedClassMixed?): String = when(value_1) { - SealedMixedChildObject1 -> "" -} - -/* - * TESTCASE NUMBER: 9 - * DISCUSSION: maybe make exhaustive without else? - */ -fun case_9(value_1: Any?): String = when (value_1) { - is Any -> "" - null -> "" -} - -/* - * TESTCASE NUMBER: 10 - * DISCUSSION - * ISSUES: KT-26044 - */ -fun case_10(value: SealedClassEmpty): String = when (value) {} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.kt index 014eec0ea2a..270201e6b75 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.2.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION // SKIP_TXT diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.fir.kt deleted file mode 100644 index e91e58f4ee1..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.fir.kt +++ /dev/null @@ -1,37 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -// SKIP_TXT - - -// TESTCASE NUMBER: 1 -fun case_1(value_1: EnumClass?): String = when(value_1) { - EnumClass.EAST -> "" - EnumClass.SOUTH -> "" - EnumClass.NORTH -> "" - EnumClass.WEST -> "" -} - -// TESTCASE NUMBER: 2 -fun case_2(value_1: EnumClass?): String = when(value_1) { - EnumClass.EAST -> "" - EnumClass.SOUTH -> "" - EnumClass.NORTH -> "" - null -> "" -} - -// TESTCASE NUMBER: 3 -fun case_3(value_1: EnumClass?): String = when(value_1) { - EnumClass.EAST, null, EnumClass.SOUTH, EnumClass.NORTH -> "" -} - -// TESTCASE NUMBER: 4 -fun case_4(value_1: EnumClassSingle): Int = when(value_1) {} - -// TESTCASE NUMBER: 5 -fun case_5(value_1: EnumClassSingle?): String = when(value_1) { - EnumClassSingle.EVERYTHING -> "" -} - -// TESTCASE NUMBER: 6 -fun case_6(value_1: EnumClassSingle?): String = when(value_1) { - null -> "" -} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.kt index 1a7f76a7371..69b5d521070 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/11.3.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION // SKIP_TXT diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.fir.kt deleted file mode 100644 index b2120411a79..00000000000 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.fir.kt +++ /dev/null @@ -1,36 +0,0 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -// SKIP_TXT - -// TESTCASE NUMBER: 1 -fun case_1(value_1: Boolean): String = when(value_1) { - true -> "" -} - -// TESTCASE NUMBER: 2 -fun case_2(value_1: Boolean): String = when(value_1) { - false -> "" -} - -// TESTCASE NUMBER: 3 -fun case_3(value_1: Boolean): Int = when(value_1) { } - -// TESTCASE NUMBER: 4 -fun case_4(value_1: Boolean): String = when { - value_1 == true -> "" - value_1 == false -> "" -} - -/* - * TESTCASE NUMBER: 5 - * DISCUSSION: maybe use const propagation here? - * ISSUES: KT-25265 - */ -fun case_5(value_1: Boolean): String { - val trueValue = true - val falseValue = false - - return when (value_1) { - trueValue -> "" - falseValue -> "" - } -} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.kt index 31e7ae51243..ab7cdda9b7b 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/3.1.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_EXPRESSION // SKIP_TXT diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/9.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/9.1.fir.kt index 64a2e11d768..03a0b7bb732 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/9.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/neg/9.1.fir.kt @@ -1,48 +1,57 @@ // !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 = when(value_1) { +fun case_1(value_1: SealedClass): String = when(value_1) { is SealedChild1 -> "" is SealedChild2 -> "" } // TESTCASE NUMBER: 2 -fun case_2(value_1: SealedClass): String = when(value_1) { +fun case_2(value_1: SealedClass): String = when(value_1) { is SealedChild1, is SealedChild2 -> "" } // TESTCASE NUMBER: 3 -fun case_3(value_1: SealedClassMixed): String = when(value_1) { +fun case_3(value_1: SealedClassMixed): String = when(value_1) { is SealedMixedChild1 -> "" is SealedMixedChild2 -> "" SealedMixedChildObject1 -> "" } // TESTCASE NUMBER: 4 -fun case_4(value_1: SealedClassMixed): String = when(value_1) { +fun case_4(value_1: SealedClassMixed): String = when(value_1) { SealedMixedChildObject1, is SealedMixedChild2, is SealedMixedChild1 -> "" } // TESTCASE NUMBER: 5 -fun case_5(value_1: SealedClassMixed): String = when(value_1) { +fun case_5(value_1: SealedClassMixed): String = when(value_1) { is SealedMixedChild1 -> "" is SealedMixedChild2 -> "" is SealedMixedChild3 -> "" } // TESTCASE NUMBER: 6 -fun case_6(value_1: SealedClassMixed): Int = when(value_1) { } +fun case_6(value_1: SealedClassMixed): Int = when(value_1) { } // TESTCASE NUMBER: 7 -fun case_7(value_1: SealedClassSingleWithObject): Int = when(value_1) { } +fun case_7(value_1: SealedClassSingleWithObject): Int = when(value_1) { } // TESTCASE NUMBER: 8 -fun case_8(value_1: SealedClassEmpty): String = when (value_1) { } +fun case_8(value_1: SealedClassEmpty): String = when (value_1) { } // TESTCASE NUMBER: 9 -fun case_9(value_1: Number): String = when (value_1) { +fun case_9(value_1: Number): String = when (value_1) { is Byte -> "" is Double -> "" is Float -> "" @@ -55,19 +64,19 @@ fun case_9(value_1: Number): String = when (value_1) { * TESTCASE NUMBER: 10 * DISCUSSION: maybe make exhaustive without else? */ -fun case_10(value_1: Any): String = when (value_1) { +fun case_10(value_1: Any): String = when (value_1) { is Any -> "" } // TESTCASE NUMBER: 11 -fun case_11(value_1: SealedClass): String = when { +fun case_11(value_1: SealedClass): String = when { value_1 is SealedChild1 -> "" value_1 is SealedChild2 -> "" value_1 is SealedChild3 -> "" } // TESTCASE NUMBER: 12 -fun case_12(value_1: SealedClassMixed): String = when(value_1) { +fun case_12(value_1: SealedClassMixed): String = when(value_1) { is SealedMixedChild1 -> "" is SealedMixedChild2 -> "" is SealedMixedChild3 -> "" diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.fir.kt new file mode 100644 index 00000000000..a6bbd1d1652 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.fir.kt @@ -0,0 +1,24 @@ +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-435 + * MAIN LINK: expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 11 + * NUMBER: 1 + * DESCRIPTION: Exhaustive when using nullable boolean values. + */ + +// TESTCASE NUMBER: 1 +fun case_1(value_1: Boolean?): String = when (value_1) { + true -> "" + false -> "" + null -> "" +} + +// TESTCASE NUMBER: 2 +fun case_2(value_1: Boolean?): String = when (value_1) { + true && false && ((true || false)) || true && !!!false && !!!true -> "" + true && false && ((true || false)) || true && !!!false -> "" + null -> "" +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.kt index c27fb8f45f7..073abe3ea85 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.1.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // SKIP_TXT /* diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.2.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.2.fir.kt index a57e44c723c..5802adafd71 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/11.2.fir.kt @@ -1,5 +1,14 @@ // SKIP_TXT +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-435 + * MAIN LINK: expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 11 + * NUMBER: 2 + * DESCRIPTION: Exhaustive when using nullable enum values. + * HELPERS: enumClasses + */ // TESTCASE NUMBER: 1 fun case_1(value_1: EnumClass?): String = when (value_1) { diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.fir.kt new file mode 100644 index 00000000000..3c414d2fff5 --- /dev/null +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.fir.kt @@ -0,0 +1,22 @@ +// SKIP_TXT + +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-100 + * MAIN LINK: expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 3 + * NUMBER: 1 + * DESCRIPTION: Exhaustive when using boolean values. + */ + +// TESTCASE NUMBER: 1 +fun case_1(value_1: Boolean): String = when (value_1) { + true -> "" + false -> "" +} + +// TESTCASE NUMBER: 2 +fun case_2(value_1: Boolean): String = when (value_1) { + true && false && ((true || false)) || true && !!!false && !!!true -> "" + true && false && ((true || false)) || true && !!!false -> "" +} diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.kt index 33c447aaad3..41f07c616de 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/exhaustive-when-expressions/p-2/pos/3.1.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // SKIP_TXT /* diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/neg/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/neg/1.1.fir.kt index df48db627e0..7b0a61a6302 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/neg/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/neg/1.1.fir.kt @@ -3,6 +3,15 @@ // SKIP_TXT // FULL_JDK +/* + * KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE) + * + * SPEC VERSION: 0.1-313 + * MAIN LINK: expressions, when-expression -> paragraph 4 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: it is possible to replace the else condition with an always-true condition + */ + // FILE: JavaEnum.java enum JavaEnum { @@ -15,7 +24,7 @@ enum JavaEnum { // TESTCASE NUMBER: 1 fun case1() { val z = JavaEnum.Val_1 - val when2 = when (z) { + val when2 = when (z) { JavaEnum.Val_1 -> { } JavaEnum.Val_1 -> { } } @@ -26,7 +35,7 @@ fun case1() { fun case2() { val b = false - val when2: Any = when (b) { + val when2: Any = when (b) { false -> { } false -> { } } @@ -36,7 +45,7 @@ fun case2() { fun case3() { val a = false - val when2: Any = when (a) { + val when2: Any = when (a) { true -> { } true -> { } } @@ -46,7 +55,7 @@ fun case3() { fun case4() { val x: SClass = SClass.B() - val when2 = when (x){ + val when2 = when (x){ is SClass.A ->{ } is SClass.B ->{ } is SClass.B ->{ } diff --git a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/pos/1.1.fir.kt b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/pos/1.1.fir.kt index 814b0720ea6..db667a1f77b 100644 --- a/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/pos/1.1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/linked/expressions/when-expression/p-4/pos/1.1.fir.kt @@ -3,6 +3,15 @@ // SKIP_TXT // FULL_JDK +/* + * KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE) + * + * SPEC VERSION: 0.1-313 + * MAIN LINK: expressions, when-expression -> paragraph 4 -> sentence 1 + * NUMBER: 1 + * DESCRIPTION: it is possible to replace the else condition with an always-true condition + */ + // FILE: JavaEnum.java enum JavaEnum { @@ -42,11 +51,11 @@ fun case2() { else -> { } } - val when2: Any = when (b) { + val when2: Any = when (b) { false -> { } !false -> { } } - val when3: Any = when (b) { + val when3: Any = when (b) { false -> { } false -> { } !false -> { } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/coercion-to-unit/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/coercion-to-unit/neg/1.fir.kt index 1cbb749a12e..e6c61bbe2e1 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/coercion-to-unit/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/coercion-to-unit/neg/1.fir.kt @@ -1,11 +1,20 @@ +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (NEGATIVE) + * + * SECTIONS: coercion-to-unit + * NUMBER: 1 + * DESCRIPTION: Coercion to Unit error diagnostics absence + * ISSUES: KT-38490 + */ + // TESTCASE NUMBER: 1 val y0 = when (2) { - else -> if (true) {""} + else -> if (true) {""} } val w:Any = TODO() val y1 = when (2) { - else -> if (true) {""} // false ok with coercion to Unit + else -> if (true) {""} // false ok with coercion to Unit } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt index 52460da9fda..aa7e83aa357 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/62.fir.kt @@ -2,6 +2,15 @@ // !DIAGNOSTICS: -UNUSED_EXPRESSION -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_VALUE -VARIABLE_WITH_REDUNDANT_INITIALIZER // SKIP_TXT +/* + * KOTLIN DIAGNOSTICS NOT LINKED SPEC TEST (POSITIVE) + * + * SECTIONS: dfa + * NUMBER: 62 + * DESCRIPTION: Raw data flow analysis test + * HELPERS: classes, objects, typealiases, functions, enumClasses, interfaces, sealedClasses + */ + /* * TESTCASE NUMBER: 1 * UNEXPECTED BEHAVIOUR @@ -145,7 +154,7 @@ fun case_10(x: Any): String { */ fun case_11(x: Any?): String? { if (x is Nothing?) { - return when(x) { + return when(x) { null -> null } } @@ -159,7 +168,7 @@ fun case_11(x: Any?): String? { */ fun case_12(x: Any?): String? { if (x == null) { - return when(x) { + return when(x) { null -> null } } @@ -173,7 +182,7 @@ fun case_12(x: Any?): String? { */ fun case_13(x: Any?): String? { if (x === null) { - return when(x) { + return when(x) { null -> null } } @@ -187,7 +196,7 @@ fun case_13(x: Any?): String? { */ fun case_14(x: Any?): String? { x as Nothing? - return when(x) { + return when(x) { null -> null } }