Files
kotlin-fork/compiler/testData/diagnostics/tests/inference/implicitInvokeWithFunctionLiteralArgument.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
796 B
Kotlin
Vendored

// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNUSED_VARIABLE
class TestClass {
inline operator fun <T> invoke(task: () -> T) = task()
}
fun <T> test(value: T, test: TestClass): T {
<!UNREACHABLE_CODE!>val x =<!> test { return value }
<!UNREACHABLE_CODE!>x checkType { _<Nothing>() }<!>
<!UNREACHABLE_CODE!>return value<!>
}
// ---
class Future<T>
interface FutureCallback<E> {
operator fun <T> invoke(f: (E) -> T): Future<T>
}
fun test(cb: FutureCallback<String>) {
val a = cb { it[0] }
a checkType { _<Future<Char>>() }
val b = cb { it }
b checkType { _<Future<String>>() }
val c = cb {}
c checkType { _<Future<Unit>>() }
cb.let { callback ->
val d = callback { it.length }
d checkType { _<Future<Int>>() }
}
}