Files
kotlin-fork/compiler/testData/diagnostics/tests/when/kt10809.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

69 lines
2.0 KiB
Kotlin
Vendored

// !WITH_NEW_INFERENCE
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEBUG_INFO_SMARTCAST
// NI_EXPECTED_FILE
/*
* KOTLIN DIAGNOSTICS SPEC TEST (POSITIVE)
*
* SPEC VERSION: 0.1-152
* PRIMARY LINKS: expressions, when-expression -> paragraph 5 -> sentence 1
* expressions, when-expression -> paragraph 6 -> sentence 1
* expressions, when-expression -> paragraph 2 -> sentence 1
* expressions, when-expression -> paragraph 9 -> sentence 1
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 1
* expressions, conditional-expression -> paragraph 4 -> sentence 1
* declarations, function-declaration -> paragraph 7 -> sentence 1
* type-inference, smart-casts, smart-cast-types -> paragraph 9 -> sentence 1
* type-system, type-kinds, type-parameters -> paragraph 4 -> sentence 1
* type-inference, local-type-inference -> paragraph 8 -> sentence 1
* type-inference, local-type-inference -> paragraph 2 -> sentence 1
*/
interface Data
interface Item
class FlagData(val value: Boolean) : Data
class ListData<T : Item>(val list: List<T>) : Data
fun <T> listOf(vararg items: T): List<T> = null!!
fun test1(o: Any) = <!TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT{OI}!>when<!> (o) {
is List<*> ->
ListData(listOf())
is Int -> when {
o < 0 ->
FlagData(true)
else ->
null
}
else ->
null
}
fun test1x(o: Any): Data? = when (o) {
is List<*> ->
ListData(listOf())
is Int -> when {
o < 0 ->
FlagData(true)
else ->
null
}
else ->
null
}
fun test2() =
<!TYPE_INFERENCE_FAILED_ON_SPECIAL_CONSTRUCT{OI}!>if<!> (true)
ListData(listOf())
else
FlagData(true)
fun test2x(): Data =
if (true) ListData(listOf()) else FlagData(true)
fun test2y(): Any =
if (true) ListData(listOf()) else FlagData(true)
fun test2z(): Any =
run { if (true) ListData(listOf()) else FlagData(true) }