Files
kotlin-fork/compiler/testData/diagnostics/tests/resolve/specialConstructions/elvisAsCall.kt
T
Denis.Zharkov 2ecba6ac39 Remove WITH_NEW_INFERENCE directive from all tests
This directive anyway does not make test run twice with OI, and with NI
It only once run the test with specific settings (// LANGUAGE)
and ignores irrelevant (OI or NI tags)
2021-05-25 13:28:26 +03:00

37 lines
991 B
Kotlin
Vendored

package a
interface A
fun doList(l: List<Int>) = l
fun doInt(i: Int) = i
fun getList(): List<Int>? = null
fun <T> strangeList(f: (T) -> Unit): List<T> = throw Exception("$f")
fun <T: A> emptyListOfA(): List<T> = throw Exception()
//-------------------------------
fun testElvis(a: Int?, b: Int?) {
if (a != null) {
doInt(b ?: <!DEBUG_INFO_SMARTCAST!>a<!>)
}
doList(getList() ?: <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED{OI}!>emptyListOfA<!>()) //should be an error
doList(getList() ?: strangeList { doInt(it) }) //lambda was not analyzed
}
fun testDataFlowInfo1(a: Int?, b: Int?) {
val c: Int = a ?: b!!
doInt(c)
// b is nullable if a != null
b <!UNSAFE_OPERATOR_CALL!>+<!> 1
}
fun testDataFlowInfo2(a: Int?, b: Int?) {
doInt(a ?: b!!)
// b is nullable if a != null
b <!UNSAFE_OPERATOR_CALL!>+<!> 1
}
fun testTypeMismatch(a: String?, b: Any) {
doInt(<!TYPE_MISMATCH{NI}!><!TYPE_MISMATCH{OI}!>a<!> ?: <!TYPE_MISMATCH{OI}!>b<!><!>)
}