Files
kotlin-fork/compiler/testData/diagnostics/tests/when/RedundantElse.kt
T
Dmitriy Novozhilov e6b5cb5216 [TD] Update diagnostics test data due to new test runners
Update includes:
- Changing syntax of `OI/`NI` tags from `<!NI;TAG!>` to `<!TAG{NI}!>`
- Fix some incorrect directives
- Change order of diagnostics in some places
- Remove ignored diagnostics from FIR test data (previously `DIAGNOSTICS` didn't work)
- Update FIR dumps in some places and add `FIR_IDENTICAL` if needed
- Replace all JAVAC_SKIP with SKIP_JAVAC directive
2020-12-16 19:52:25 +03:00

81 lines
1.7 KiB
Kotlin
Vendored

/*
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
*
* SPEC VERSION: 0.1-152
* PRIMARY LINKS: expressions, when-expression -> paragraph 5 -> sentence 1
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 3
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 6
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 9
* expressions, when-expression -> paragraph 6 -> sentence 10
* expressions, when-expression -> paragraph 6 -> sentence 11
*/
// FILE: MyEnum.java
public enum MyEnum {
SINGLE;
public static MyEnum getInstance() {
return SINGLE;
}
}
// FILE: test.kt
sealed class X {
class A : X()
class B : X()
}
fun foo(x: X) = when (x) {
is X.A -> {}
is X.B -> {}
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> {}
}
fun bar(x: X?): String = when (x) {
is X.A -> "A"
is X.B -> "B"
null -> "null"
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> "Unreachable"
}
fun justUse(x: X) {
when (x) {
is X.A -> {}
is X.B -> {}
// Redundant even in statement position
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> {}
}
}
enum class E {
A, B
}
fun foo(e: E): String = when (e) {
E.A -> "A"
E.B -> "B"
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> ""
}
fun bar(e: E?): String = when (e) {
E.A -> "A"
E.B -> "B"
else -> "" // no warning
}
fun foo(b: Boolean) = when (b) {
true -> 1
false -> 0
<!REDUNDANT_ELSE_IN_WHEN!>else<!> -> -1
}
fun useJava(): String {
val me = MyEnum.getInstance()
return when (me) {
MyEnum.SINGLE -> "OK"
else -> "FAIL" // no warning
}
}