FIR: Adjust testData for spec tests: when-expression

This commit is contained in:
Denis Zharkov
2020-04-15 13:07:41 +03:00
parent 0d34299b7a
commit 06bae1e52f
36 changed files with 2820 additions and 0 deletions
@@ -0,0 +1,38 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 1
* NUMBER: 1
* DESCRIPTION: 'When' with bound value and type test condition (without companion object in classes), but without type checking operator.
* HELPERS: classes
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Any): String {
when (value_1) {
EmptyClass -> return ""
}
return ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Any): String {
when (value_1) {
Any -> return ""
}
return ""
}
// TESTCASE NUMBER: 3
fun case_3(value_1: Any): String {
when (value_1) {
Nothing -> return ""
}
return ""
}
@@ -0,0 +1,20 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 1
* NUMBER: 2
* DESCRIPTION: 'When' with bound value and type test condition on the non-type operand of the type checking operator.
* HELPERS: classes
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Any, value_2: Int): String {
when (value_1) {
is value_2 -> return ""
}
return ""
}
@@ -0,0 +1,35 @@
// !DIAGNOSTICS: -UNUSED_VALUE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-201
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 11
* NUMBER: 1
* DESCRIPTION: 'When' with bound value and non-expressions in 'when condition'.
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Int, value_2: List<Int>): String {
when (value_1) {
<!EXPRESSION_EXPECTED!>while (false) {}<!> -> return ""
<!EXPRESSION_EXPECTED!>do {} while (false)<!> -> return ""
<!EXPRESSION_EXPECTED!>for (value in value_2) {}<!> -> return ""
}
return ""
}
// TESTCASE NUMBER: 4
fun case_4(value_1: Int): String {
var value_2: Int
var value_3 = 10
when (value_1) {
<!ASSIGNMENT_IN_EXPRESSION_CONTEXT!>value_2 = 10<!> -> return ""
<!ASSIGNMENT_IN_EXPRESSION_CONTEXT!>value_3 %= 10<!> -> return ""
}
return ""
}
@@ -0,0 +1,33 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-201
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 12
* NUMBER: 1
* DESCRIPTION: 'When' without bound value and with 'else' branch not in the last position.
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Int): String = when {
else -> ""
value_1 == 1 -> ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Int): String = when {
value_1 == 1 -> ""
else -> ""
value_1 == 2 -> ""
}
// TESTCASE NUMBER: 3
fun case_3(): String {
when {
else -> return ""
else -> return ""
}
return ""
}
@@ -0,0 +1,21 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 3
* NUMBER: 1
* DESCRIPTION: 'When' with bound value and 'when condition' with range expression, but without containment checking operator.
* HELPERS: typesProvider
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Int, value_2: TypesProvider): String {
when (value_1) {
-1000L..100 -> return ""
value_2.getInt()..getLong() -> return ""
}
return ""
}
@@ -0,0 +1,36 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 3
* NUMBER: 2
* DESCRIPTION: 'When' with bound value and 'when condition' with contains operator and type without defined contains operator.
* HELPERS: classes
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Int, value_2: EmptyClass, value_3: Int, value_4: Any): String {
when (value_1) {
<!INAPPLICABLE_CANDIDATE!>in<!> value_2 -> return ""
<!INAPPLICABLE_CANDIDATE!>in<!> value_3 -> return ""
<!INAPPLICABLE_CANDIDATE!>in<!> value_4 -> return ""
}
return ""
}
/*
* TESTCASE NUMBER: 2
* DISCUSSION
* ISSUES: KT-25948
*/
fun case_2(value_1: Int, value_3: Nothing) {
when (value_1) {
<!AMBIGUITY!>in<!> value_3 -> {}
<!AMBIGUITY!>in<!> throw Exception() -> {}
<!AMBIGUITY!>in<!> return -> {}
}
}
@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-313
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 7
* NUMBER: 1
* DESCRIPTION: 'When' with bound value and with else branch not in the last position.
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Int): String = when (value_1) {
else -> ""
1 -> ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Int): String = when (value_1) {
1 -> ""
else -> ""
2 -> ""
}
// TESTCASE NUMBER: 3
fun case_3(value_1: Int): String {
when (value_1) {
else -> return ""
else -> return ""
}
return ""
}
@@ -0,0 +1,69 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 1
* NUMBER: 1
* DESCRIPTION: 'When' with bound value and type test condition.
* HELPERS: classes, objects
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Any): String {
when (value_1) {
is Int -> return ""
is Float -> return ""
is Double -> return ""
is String -> return ""
is Char -> return ""
is Boolean -> return ""
}
return ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Any?): String = when (value_1) {
is Int? -> "" // if value is null then this branch will be executed
is Float -> ""
else -> ""
}
// TESTCASE NUMBER: 3
fun case_3(value_1: Any?): String = when (value_1) {
is Any -> ""
else -> ""
}
// TESTCASE NUMBER: 4
fun case_4(value_1: Any): String = when (value_1) {
is Any? -> ""
else -> ""
}
/*
* TESTCASE NUMBER: 5
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-22996
*/
fun case_5(value_1: Any?): String = when (value_1) {
is Double -> ""
is Int? -> "" // if value is null then this branch will be executed
is String -> ""
is Float? -> "" // redundant nullable type check
is Char -> ""
is Boolean -> ""
else -> ""
}
// TESTCASE NUMBER: 6
fun case_6(value_1: Any): String {
when (value_1) {
is EmptyObject -> return ""
is ClassWithCompanionObject.Companion -> return ""
}
return ""
}
@@ -0,0 +1,58 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 1
* NUMBER: 2
* DESCRIPTION: 'When' with bound value and type test condition (invert type checking operator).
* HELPERS: classes, sealedClasses, objects
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: SealedClass) = when (value_1) {
!is SealedChild1 -> {}
!is SealedChild2 -> {}
!is SealedChild3 -> {}
}
/*
* TESTCASE NUMBER: 2
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-22996
*/
fun case_2(value_1: SealedClass?): String = when (value_1) {
!is SealedChild2 -> "" // including null
is SealedChild2 -> ""
null -> "" // redundant
}
// TESTCASE NUMBER: 3
fun case_3(value_1: SealedClass?): String = when (value_1) {
!is SealedChild2? -> "" // null isn't included
is SealedChild2 -> ""
null -> ""
}
/*
* TESTCASE NUMBER: 4
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-22996
*/
fun case_4(value_1: SealedClass?) {
when (value_1) {
!is SealedChild2 -> {} // including null
is SealedChild2? -> {} // redundant nullable type check
}
}
// TESTCASE NUMBER: 5
fun case_5(value_1: Any): String {
when (value_1) {
is EmptyObject -> return ""
!is ClassWithCompanionObject.Companion -> return ""
}
return ""
}
@@ -0,0 +1,59 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-296
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 1
* NUMBER: 4
* DESCRIPTION: 'When' with bound value and enumaration of type test conditions (with invert type checking operator).
* HELPERS: sealedClasses
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: SealedClass): String = when (value_1) {
is SealedChild1, !is SealedChild3 -> ""
is SealedChild3 -> ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: SealedClass) = when (value_1) {
!is SealedChild1, !is SealedChild2, !is SealedChild3 -> {}
}
// TESTCASE NUMBER: 3
fun case_3(value_1: SealedClass): String = when (value_1) {
is SealedChild2, !is SealedChild2 -> ""
}
// TESTCASE NUMBER: 4
fun case_4(value_1: SealedClass): String = when (value_1) {
!is SealedChild1, is SealedChild1 -> ""
}
// TESTCASE NUMBER: 5
fun case_5(value_1: Any?): String = when (value_1) {
is SealedChild3, !is SealedChild3? -> ""
else -> ""
}
/*
* TESTCASE NUMBER: 6
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-22996
*/
fun case_6(value_1: Any?): String = when (value_1) {
is Boolean?, !is SealedChild3 -> "" // double nullable type check in the one branch
is SealedChild3 -> ""
else -> ""
}
/*
* TESTCASE NUMBER: 7
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-22996
*/
fun case_7(value_1: Any?): String = when (value_1) {
is Number?, null, !is SealedChild3 -> "" // triple nullable type check in the one branch
else -> ""
}
@@ -0,0 +1,286 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-201
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 10
* NUMBER: 1
* DESCRIPTION: 'When' with enumeration of the different variants of expressions in 'when condition'.
* HELPERS: typesProvider, classes, functions
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Any?) {
when (value_1) {
true -> {}
100 -> {}
-.09f -> {}
'.' -> {}
"..." -> {}
null -> {}
}
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Number, value_2: Int) {
when (value_1) {
-.09 % 10L -> {}
value_2 / -5 -> {}
getByte() - 11 + 90 -> {}
}
}
// TESTCASE NUMBER: 3
fun case_3(value_1: Boolean, value_2: Boolean, value_3: Long) {
when (value_1) {
value_2 -> {}
!value_2 -> {}
getBoolean() && value_2 -> {}
getChar() != 'a' -> {}
getList() === getAny() -> {}
value_3 <= 11 -> {}
}
}
// TESTCASE NUMBER: 4
fun case_4(value_1: String, value_2: String, value_3: String) {
when (value_1) {
"..." + value_2 + "" + "$value_3" + "..." -> {}
value_2 + getString() -> {}
}
}
// TESTCASE NUMBER: 5
fun case_5(value_1: Int, value_2: Int, value_3: Boolean?) {
when (value_1) {
when {
value_2 > 1000 -> 1
value_2 > 100 -> 2
else -> 3
} -> {}
when (value_3) {
true -> 1
false -> 2
null -> 3
} -> {}
when (value_3!!) {
true -> 1
false -> 2
} -> {}
}
}
// TESTCASE NUMBER: 6
fun case_6(value_1: Int, value_2: Int) {
when (value_1) {
if (value_2 > 1000) 1
else 2 -> {}
if (value_2 < 100) 1
else if (value_2 < 10) 2
else 3 -> {}
}
}
// TESTCASE NUMBER: 7
fun case_7(value_1: Any, value_2: String, value_3: String) {
when (value_1) {
try { 4 } catch (e: Exception) { 5 } -> {}
try { throw Exception() } catch (e: Exception) { value_2 } -> {}
try { throw Exception() } catch (e: Exception) { {value_3} } finally { } -> {}
}
}
// TESTCASE NUMBER: 8
fun case_8(value_1: Int, value_2: Int?, value_3: Int?) {
when (value_1) {
value_2 ?: 0 -> {}
value_2 ?: value_3 ?: 0 -> {}
value_2!! ?: 0 -> {}
}
}
// TESTCASE NUMBER: 9
fun case_9(value_1: Any) {
when (value_1) {
1..10 -> {}
-100L..100L -> {}
-getInt()..getLong() -> {}
}
}
// TESTCASE NUMBER: 10
fun case_10(value_1: Collection<Int>, value_2: Collection<Int>, value_3: Collection<Int>?) {
when (value_1) {
value_2 as List<Int> -> {}
value_2 as? List<Int> -> {}
value_3 as? MutableMap<Int, Int> -> {}
(value_2 as? Map<Int, Int>) as MutableMap<Int, Int> -> {}
}
}
// TESTCASE NUMBER: 11
fun case_11(value_1: Any, value_2: Int, value_3: Int, value_4: Boolean) {
var mutableValue1 = value_2
var mutableValue2 = value_3
when (value_1) {
++mutableValue1 -> {}
--mutableValue2 -> {}
!value_4 -> {}
}
}
// TESTCASE NUMBER: 12
fun case_12(value_1: Int, value_2: Int, value_3: Int, value_4: Int?) {
var mutableValue1 = value_2
var mutableValue2 = value_3
when (value_1) {
mutableValue1++ -> {}
mutableValue2-- -> {}
value_4!! -> {}
}
}
// TESTCASE NUMBER: 13
fun case_13(value_1: Int, value_2: List<Int>, value_3: List<List<List<List<Int>>>>) {
when (value_1) {
value_2[0] -> {}
value_3[0][-4][1][-1] -> {}
}
}
// TESTCASE NUMBER: 14
fun case_14(value_1: Any, value_2: Class, value_3: Class?, value_4: Int) {
fun __fun_1(): () -> Any { return fun() { } }
when (value_1) {
funWithoutArgs() -> {}
__fun_1()() -> {}
value_2.fun_2(value_4) -> {}
value_3?.fun_2(value_4) -> {}
value_3!!.fun_2(value_4) -> {}
}
}
// TESTCASE NUMBER: 15
fun case_15(value_1: Int, value_2: Class, value_3: Class?) {
when (value_1) {
value_2.prop_1 -> {}
value_3?.prop_2 -> {}
value_2::prop_1.get() -> {}
value_3!!::prop_3.get() -> {}
}
}
// TESTCASE NUMBER: 16
fun case_16(value_1: () -> Any): Any {
val fun_1 = fun() { return }
return when (value_1) {
fun() {} -> {}
fun() { return } -> {}
fun(): () -> Unit { return fun() {} } -> {}
fun_1 -> {}
else -> {}
}
}
// TESTCASE NUMBER: 17
fun case_17(value_1: () -> Any) {
val lambda_1 = { 0 }
when (value_1) {
lambda_1 -> {}
{ { {} } } -> {}
{ -> (Int)
{ arg: Int -> { { println(arg) } } }
} -> {}
}
}
// TESTCASE NUMBER: 18
fun case_18(value_1: Any) {
val object_1 = object {
val prop_1 = 1
}
when (value_1) {
object {} -> {}
object {
private fun fun_1() { }
val prop_1 = 1
} -> {}
object_1 -> {}
}
}
// TESTCASE NUMBER: 19
class A {
val prop_1 = 1
val lambda_1 = { 1 }
fun fun_1(): Int { return 1 }
fun case_19(value_1: Any) {
when (value_1) {
this -> {}
((this)) -> {}
this::prop_1.get() -> {}
this.prop_1 -> {}
this.lambda_1() -> {}
this::lambda_1.get()() -> {}
this.fun_1() -> {}
this::fun_1.invoke() -> {}
}
}
}
// TESTCASE NUMBER: 20
fun case_20(value_1: Nothing) {
when (value_1) {
throw Exception() -> {}
throw throw throw Exception() -> {}
}
}
// TESTCASE NUMBER: 21
fun case_21(value_1: Nothing) {
fun f1() {
when (value_1) {
return -> 1
return return return -> 2
}
}
fun f2(): List<Int>? {
when (value_1) {
return listOf(0, 1, 2) -> 1
return null -> 2
}
}
}
// TESTCASE NUMBER: 22
fun case_22(value_1: Nothing) {
loop1@ while (true) {
loop2@ while (true) {
when (value_1) {
continue@loop1 -> 1
continue@loop2 -> 2
}
}
}
}
// TESTCASE NUMBER: 23
fun case_23(value_1: Nothing) {
loop1@ while (true) {
loop2@ while (true) {
when (value_1) {
break@loop1 -> 1
break@loop2 -> 2
}
}
}
}
@@ -0,0 +1,263 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-201
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 10
* NUMBER: 2
* DESCRIPTION: 'When' with different variants of the arithmetic expressions (additive expression and multiplicative expression) in 'when condition'.
* HELPERS: typesProvider, classes, functions
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Any?) {
when (value_1) {
true, 100, -.09f -> {}
'.', "...", null -> {}
}
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Number, value_2: Int) {
when (value_1) {
-.09 % 10L, value_2 / -5, getByte() - 11 + 90 -> {}
}
}
// TESTCASE NUMBER: 3
fun case_3(value_1: Boolean, value_2: Boolean, value_3: Long) {
when (value_1) {
value_2, !value_2, getBoolean() && value_2, getChar() != 'a' -> {}
getList() === getAny(), value_3 <= 11 -> {}
}
}
// TESTCASE NUMBER: 4
fun case_4(value_1: String, value_2: String, value_3: String) {
when (value_1) {
"..." + value_2 + "" + "$value_3" + "...", value_2 + getString() -> {}
}
}
// TESTCASE NUMBER: 5
fun case_5(value_1: Int, value_2: Int, value_3: Boolean?) {
when (value_1) {
when {
value_2 > 1000 -> 1
value_2 > 100 -> 2
else -> 3
}, when (value_3) {
true -> 1
false -> 2
null -> 3
}, when (value_3!!) {
true -> 1
false -> 2
} -> {}
}
}
// TESTCASE NUMBER: 6
fun case_6(value_1: Int, value_2: Int) {
when (value_1) {
if (value_2 > 1000) 1 else 2, if (value_2 < 100) 1 else if (value_2 < 10) 2 else 3 -> {}
}
}
// TESTCASE NUMBER: 7
fun case_7(value_1: Any, value_2: String, value_3: String) {
when (value_1) {
try { 4 } catch (e: Exception) { 5 }, try { throw Exception() } catch (e: Exception) { value_2 }, try { throw Exception() } catch (e: Exception) { {value_3} } finally { } -> {}
}
}
// TESTCASE NUMBER: 8
fun case_8(value_1: Int, value_2: Int?, value_3: Int?) {
when (value_1) {
value_2 ?: 0, value_2 ?: value_3 ?: 0, value_2!! ?: 0 -> {}
}
}
// TESTCASE NUMBER: 9
fun case_9(value_1: Any) {
when (value_1) {
1..10, -100L..100L, -getInt()..getLong() -> {}
}
}
// TESTCASE NUMBER: 10
fun case_10(value_1: Collection<Int>, value_2: Collection<Int>, value_3: Collection<Int>?) {
when (value_1) {
value_2 as List<Int>, value_2 as? List<Int> -> {}
value_3 as? MutableMap<Int, Int>, (value_2 as? Map<Int, Int>) as MutableMap<Int, Int> -> {}
}
}
// TESTCASE NUMBER: 11
fun case_11(value_1: Any, value_2: Int, value_3: Int, value_4: Boolean) {
var mutableValue1 = value_2
var mutableValue2 = value_3
when (value_1) {
++mutableValue1, --mutableValue2, !value_4 -> {}
}
}
// TESTCASE NUMBER: 12
fun case_12(value_1: Int, value_2: Int, value_3: Int, value_4: Int?) {
var mutableValue1 = value_2
var mutableValue2 = value_3
when (value_1) {
mutableValue1++, mutableValue2--, value_4!! -> {}
}
}
// TESTCASE NUMBER: 13
fun case_13(value_1: Int, value_2: List<Int>, value_3: List<List<List<List<Int>>>>) {
when (value_1) {
value_2[0], value_3[0][-4][1][-1] -> {}
}
}
// TESTCASE NUMBER: 14
fun case_14(value_1: Any, value_2: Class, value_3: Class?, value_4: Int) {
fun __fun_1(): () -> Unit { return fun() { } }
when (value_1) {
funWithoutArgs(), __fun_1()(), value_2.fun_2(value_4) -> {}
value_3?.fun_2(value_4), value_3!!.fun_2(value_4) -> {}
}
}
// TESTCASE NUMBER: 15
fun case_15(value_1: Int, value_2: Class, value_3: Class?) {
when (value_1) {
value_2.prop_1, value_3?.prop_2 -> {}
value_2::prop_1.get(), value_3!!::prop_3.get() -> {}
}
}
// TESTCASE NUMBER: 16
fun case_16(value_1: () -> Any): Any {
val fun_1 = fun() { return }
return when (value_1) {
fun() {}, fun() { return }, fun(): () -> Unit { return fun() {} }, fun_1 -> {}
else -> {}
}
}
// TESTCASE NUMBER: 17
fun case_17(value_1: () -> Any) {
val lambda_1 = { 0 }
when (value_1) {
lambda_1, { { {} } }, { -> (Int)
{ arg: Int -> { { println(arg) } } } } -> {}
}
}
// TESTCASE NUMBER: 18
fun case_18(value_1: Any) {
val object_1 = object {
val prop_1 = 1
}
when (value_1) {
object {}, object {
private fun fun_1() { }
val prop_1 = 1
}, object_1 -> {}
}
}
// TESTCASE NUMBER: 19
class A {
val prop_1 = 1
val lambda_1 = { 1 }
fun fun_1(): Int { return 1 }
fun case_19(value_1: Any) {
when (value_1) {
this, ((this)), this::prop_1.get() -> {}
this.prop_1, this.lambda_1() -> {}
this::lambda_1.get()(), this.fun_1(), this::fun_1.invoke() -> {}
}
}
}
// TESTCASE NUMBER: 20
fun case_20(value_1: Nothing) {
when (value_1) {
throw Exception(), throw throw throw Exception() -> {}
}
}
// TESTCASE NUMBER: 21
fun case_21(value_1: Nothing) {
fun f1() {
when (value_1) {
return, return return return -> 2
}
}
fun f2(): List<Int>? {
when (value_1) {
return listOf(0, 1, 2), return null -> 2
}
}
}
// TESTCASE NUMBER: 22
fun case_22(value_1: Nothing) {
loop1@ while (true) {
loop2@ while (true) {
when (value_1) {
continue@loop1, continue@loop2 -> 2
}
}
}
}
// TESTCASE NUMBER: 23
fun case_23(value_1: Nothing) {
loop1@ while (true) {
loop2@ while (true) {
when (value_1) {
break@loop1, break@loop2 -> 2
}
}
}
}
// TESTCASE NUMBER: 24
fun case_24(value_1: Nothing?) = when (value_1) {
throw Exception(), return "" -> ""
null, return return return "", throw throw throw Exception() -> ""
else -> ""
}
/*
* TESTCASE NUMBER: 25
* DISCUSSION
* ISSUES: KT-25948
*/
fun case_25(value_1: Boolean) = when (value_1) {
true -> {}
throw Exception(), return -> {}
false, return return return, throw throw throw Exception() -> {}
}
/*
* TESTCASE NUMBER: 26
* UNEXPECTED BEHAVIOUR
* ISSUES: KT-26045
*/
fun case_26(value_1: Int?, value_2: Class, value_3: Class?) {
when (value_1) {
value_2.prop_1, value_3?.prop_1 -> {}
10 -> {}
}
}
@@ -0,0 +1,32 @@
// SKIP_TXT
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-201
* PLACE: expressions, when-expression -> paragraph 6 -> sentence 11
* NUMBER: 1
* DESCRIPTION: 'When' with bound value and not allowed break and continue expression (without labels) in 'when condition'.
*/
// TESTCASE NUMBER: 1
fun case_1(value_1: Int): String {
while (true) {
when (value_1) {
break -> return ""
}
}
return ""
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Int): String {
while (true) {
when (value_1) {
continue -> return ""
}
}
return ""
}