Fix error type for implicit invoke with function literal argument

#KT-11401 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-01-09 22:02:54 +03:00
parent 9ff8192aff
commit cff0865c87
22 changed files with 347 additions and 7 deletions
@@ -0,0 +1,37 @@
// !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>>() }
}
}