import kotlin.reflect.KFunction1 // !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER fun foo(i: Int) {} fun foo(s: String) {} fun foo2(i: Int) {} fun foo3(i: Number) {} fun id(x: K): K = x fun id1(x: K): K = x fun id2(x: L): L = x fun baz1(x: T, y: T): T = TODO() fun baz2(x: T, y: Inv): T = TODO() fun select(vararg x: T) = x[0] fun takeInterdependentLambdas(x: (T) -> R, y: (R) -> T) {} fun takeDependentLambdas(x: (T) -> Int, y: (Int) -> T) {} class Inv(val x: T) fun test1() { val x1: (Int) -> Unit = id(id(::foo)) val x2: (Int) -> Unit = baz1(id(::foo), ::foo) val x3: (Int) -> Unit = baz1(id(::foo), id(id(::foo))) val x4: (String) -> Unit = baz1(id(::foo), id(id(::foo))) id<(Int) -> Unit>(id(id(::foo))) id(id<(Int) -> Unit>(::foo)) baz1<(Int) -> Unit>(id(::foo), id(id(::foo))) baz1(id(::foo), id(id<(Int) -> Unit>(::foo))) baz1(id(::foo), id<(Int) -> Unit>(id(::foo))) baz1(id { it.inv() }, id<(Int) -> Unit> { }) baz1(id1 { x -> x.inv() }, id2 { x: Int -> }) baz1(id1 { it.inv() }, id2 { x: Int -> }) baz2(id1 { it.inv() }, id2(Inv { x: Int -> })) select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2 { x: Int -> x })) select(id1 { it.inv() }, id1 { x: Number -> TODO() }, id1(id2(::foo2))) select(id1 { x: Inv -> TODO() }, id1 { ")!>it.x.inv() }, id1 { x: Inv -> TODO() }) select(id1 { & Inv}")!>it }, id1 { x: Inv -> TODO() }, id1 { x: Inv -> TODO() }) ")!>select(id1(::foo), id(::foo3), id1(id2(::foo2))) select({ it }, { x: Int -> TODO() }) // Interdependent postponed arguments are unsupported takeInterdependentLambdas({}, {}) takeInterdependentLambdas({ it }, { 10 }) takeInterdependentLambdas({ 10 }, { it }) takeInterdependentLambdas({ 10 }, { x -> x }) takeInterdependentLambdas({ x -> 10 }, { it }) takeInterdependentLambdas({ it }, { x -> 10 }) takeDependentLambdas({ it }, { it }) takeDependentLambdas({ it.length }, { "it" }) takeDependentLambdas({ it; 10 }, { }) select({ it }, fun(x: Int) = 1) val x5: (Int) -> Unit = select({ it }, { x: Number -> Unit }) val x6 = select(id { it }, id(id<(Int) -> Unit> { x: Number -> Unit })) select(id(id2 { it.inv() }), id(id { x: Int -> x })) val x7: (Int) -> Unit = selectNumber(id {}, id {}, id {}) val x8: (Int) -> Unit = selectNumber(id { x -> x }, id { x -> }, id { x -> }) val x9: (Int) -> Unit = selectNumber(id { }, id { x -> }, id { it }) val x10: (Int) -> Unit = selectFloat(id { }, id { x -> }, id { & Number}")!>it }) val x11: (B) -> Unit = selectC(id { }, id { x -> x }, id { it }) /* * Upper constraint is less specific than lower (it's error): * K <: (A) -> Unit -> TypeVariable(_RP1) >: A * K >: (C) -> TypeVariable(_R) -> TypeVariable(_RP1) <: C */ val x12 = selectC(id { it }, id { x: B -> }) val x13 = selectA(id { it }, id { x: C -> }) // one upper constraint and one lower val x14 = selectC(id { it }, id { x: A -> }, { x -> x }) val x15 = selectC(id { it }, { x: A -> }, id { x -> x }) /* * Two upper constraints and one lower * K <: (C) -> Unit -> TypeVariable(_RP1) >: C * K <: (B) -> Unit -> TypeVariable(_RP1) >: B * K >: (A) -> TypeVariable(_R) -> TypeVariable(_RP1) <: A * K == intersect(CST(C, B), A) == A */ val x16: (C) -> Unit = selectB(id { it }, { x -> }, id { x: A -> x }) /* * two upper constraints and one equality (it's error) * K <: (C) -> Unit -> TypeVariable(_RP1) >: C * K == (B) -> Unit -> TypeVariable(_RP1) == B */ val x17: (C) -> Unit = selectB(id { it }, id { it }, id<(B) -> Unit> { x -> x }) val x18: (C) -> Unit = select(id { it }, { it }, id<(B) -> Unit> { x -> x }) val x19: String.() -> Unit = select( kotlin.Unit")!>id {}, kotlin.Unit")!>id(fun(x: String) {})) val x20: String.() -> Unit = select( kotlin.Unit")!>{}, kotlin.Unit")!>(fun(x: String) {})) val x21: String.() -> Unit = select( kotlin.Unit")!>id(fun(x: String) {}), kotlin.Unit")!>id(fun(x: String) {})) val x22 = select(id Unit>(fun(x: String) {}), kotlin.Unit")!>id(fun(x: String) {})) val x23 = select( kotlin.Unit")!>id(fun String.(x: String) {}), kotlin.Unit")!>id(fun(x: String, y: String) {})) val x24 = select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x: String -> this }) val x25 = select(id(fun String.(x: String) {}), id(fun(x: String, y: String) { }), { x: String, y: String -> x }) // It isn't related with posponed arguments, see KT-38439 val x26: Int.(String) -> Int = fun (x: String) = 10 val x27: Int.(String) -> Int = id(fun (x: String) = 10) val x28 = select(id { x, y -> x.inv() + y.toByte() }, { x: Int, y -> y.toByte() }, { x, y: Number -> x.inv() }) val x29 = select(id { x, y -> x.inv() + y.toByte() }, id { x: Int, y -> y.toByte() }, id { x, y: Number -> x.inv() }) val x30 = select({ x, y -> x.inv() + y.toByte() }, id { x: Int, y -> y.toByte() }, id { x, y: Number -> x.inv() }) val x31 = select( id { x, y -> x.inv() + y.toByte() }, id<(Int, Number) -> Int> { x, y -> x.inv() }, {} as (Number, Number) -> Int ) val x32 = selectPosponedArgument({ it }, { x: Int -> }, { x: Nothing -> x }) val x33 = selectPosponedArgument({ it }, { } as (Int) -> Unit, { x: Nothing -> x }) val x34 = selectPosponedArgument({ it }, { } as (Nothing) -> Unit, { x: Int -> x }) val x35 = selectPosponedArgument({ it }, { } as (Int) -> Unit, { } as (Nothing) -> Unit) val x36 = selectPosponedArgument3({ it }, { it }, { x: Int -> x }) val x37 = selectPosponedArgument3({ it }, { x: Number -> x }, { x: Int -> x }) val x38 = selectPosponedArgument3Revert({ it }, { it }, { x: Int -> x }) val x39 = selectPosponedArgument3Revert({ it }, { x: Number -> x }, { x: Int -> x }) val x40 = select(id Unit> {}, { x: Int, y: String -> x }) val x41 = select(A2(), { a, b, c -> a; b; c }) val x42 = select(A3(), { it }, { a -> a }) val x43 = select(A3(), ")!>A3::foo1) val x44 = select(A3(), ")!>A3::foo1, { a -> a }, { it -> it }) val x45 = select(A4(), { x: Number -> "" }) val x46 = select(A5(), { x: Number, y: Int -> "" }) val x47 = select(A2(), id { a, b, c -> a; b; c }) val x48 = select(id(A3()), { it }, { a -> a }) val x49 = select(A3(), id(")!>A3::foo1)) val x50 = select(A3(), ")!>A3::foo1, { a -> a }, { it -> it }) val x51 = select(A4(), id { x: Number -> x }) val x52 = select(id(A5()), id { x: Number, y: Int -> x;y }) val x53 = select(id(A5()), id { x, y -> x;y }) val x54 = select(id(")!>A5()), id { x: Number, y: Int -> x;y }) val x55: Function2 = select(id(A5()), id { x, y -> x;y; 1f }) } fun Unit> selectNumber(arg1: T, arg2: T, arg3: T) = arg1 fun Unit> selectFloat(arg1: T, arg2: T, arg3: T) = arg2 fun Unit> selectA(arg1: T, arg2: T, arg3: T) = arg2 fun Unit> selectB(arg1: T, arg2: T, arg3: T) = arg2 fun Unit> selectC(arg1: T, arg2: T, arg3: T) = arg2 fun selectPosponedArgument(vararg x: (T) -> Unit) = x[0] fun selectPosponedArgument3(x: (T) -> Unit, y: (R) -> Unit, z: (L) -> Unit) = x fun selectPosponedArgument3Revert(x: (T) -> Unit, y: (R) -> Unit, z: (L) -> Unit) = x interface A class B: A class C: A class A2: Function3 { override fun invoke(p1: Int, p2: String, p3: Float): Float = 4f } class A3: KFunction1 { override fun invoke(p1: Number): String = TODO() override val name: String = TODO() fun foo1(x: Int) {} fun foo1(x: Any?) {} } class A4: Function1 { override fun invoke(p1: Int): Float = TODO() } class A5: Function2 { override fun invoke(p1: K, p2: Q): Float = 5f }