Files
kotlin-fork/compiler/testData/ir/irText/expressions/callableReferences/caoWithAdaptationForSam.kt
T
Dmitry Petrov bf9673a0a2 PSI2IR: SAM conversion should be performed once for index variables
Given esoteric code as in 'caoWithAdaptationForSam.kt', we should make
sure that we pass same objects to 'get' and 'set'.
2020-01-29 15:30:07 +03:00

47 lines
798 B
Kotlin
Vendored

// !LANGUAGE: +NewInference +FunctionReferenceWithDefaultValueAsOtherType +FunctionalInterfaceConversion +SamConversionPerArgument +SamConversionForKotlinFunctions
fun interface IFoo {
fun foo(i: Int)
}
fun interface IFoo2 : IFoo
object A
object B
operator fun A.get(i: IFoo) = 1
operator fun A.set(i: IFoo, newValue: Int) {}
operator fun B.get(i: IFoo) = 1
operator fun B.set(i: IFoo2, newValue: Int) {}
fun withVararg(vararg xs: Int) = 42
fun test1() {
A[::withVararg] += 1
}
fun test2() {
B[::withVararg] += 1
}
fun test3(fn: (Int) -> Unit) {
A[fn] += 1
}
fun test4(fn: (Int) -> Unit) {
if (fn is IFoo) {
A[fn] += 1
}
}
fun test5(a: Any) {
a as (Int) -> Unit
A[a] += 1
}
fun test6(a: Any) {
a as (Int) -> Unit
a as IFoo
A[a] += 1
}