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'.
This commit is contained in:
Dmitry Petrov
2020-01-28 17:12:50 +03:00
parent e750528551
commit bf9673a0a2
14 changed files with 689 additions and 125 deletions
@@ -0,0 +1,47 @@
// !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
}