Basic support of partially specified type arguments though a new underscore operator for type arguments

^KT-13394
This commit is contained in:
Victor Petukhov
2021-10-21 14:23:25 +03:00
parent e057831f7f
commit b69fb6779f
35 changed files with 1212 additions and 9 deletions
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun <K, T> foo(x: (K) -> T): Pair<K, T> = (1 as K) to (1f as T)
class `_` {}
fun box(): String {
val x1 = foo<Int, `_`> { it.toFloat() as `_` } // Pair<Int, Float>
return "OK"
}
@@ -0,0 +1,21 @@
// WITH_RUNTIME
// TARGET_BACKEND: JVM
abstract class SomeClass<T> {
abstract fun execute() : T
}
class SomeImplementation : SomeClass<String>() {
override fun execute(): String = "Test"
}
object Runner {
inline fun <reified S: SomeClass<T>, T> run() : T {
return S::class.java.newInstance().execute()
}
}
fun box(): String {
val s = Runner.run<SomeImplementation, _>() // T is inferred to String
return "OK"
}
@@ -0,0 +1,11 @@
sealed class MyResult<out T>{
data class Success<T>(val value: T): MyResult<T>()
data class Failure(val exception: Throwable): MyResult<Nothing>()
}
inline fun <reified E: Throwable, T> MyResult<T>.catch(result: (E) -> T) = "OK"
fun box(): String {
val result: MyResult<Int> = MyResult.Success(1)
return result.catch<IllegalStateException, _>{ 2 } // T is inferred into Int
}
@@ -0,0 +1,27 @@
interface RProps
open class RComponent<K, T> : Component<K, T>
interface RState
interface Component<K1, K2>
class RElementBuilder<A>
interface ReactElement
class RBuilder
interface MyProps<T> : RProps {
var list: List<T>
}
class MyComponent<T> : RComponent<MyProps<T>, RState>() {}
inline fun <P : RProps, reified C : Component<P, *>> child(
noinline handler: RElementBuilder<P>.() -> Unit
): String = "OK"
fun box(): String {
child<MyProps<RBuilder.(String) -> Unit>, _> {
}
return child<_, MyComponent<RBuilder.(String) -> Unit>> {
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
fun <K, T> foo(x: (K) -> T): Pair<K, T> = (1 as K) to (1f as T)
//class `_` {}
fun box(): String {
val x = foo<Int, _> { it.toFloat() } // Pair<Int, Float>
return "OK"
}