Keep track of synthetic accessor parameter types

Accessor parameter types may be different from callee parameter types
in case of generic methods specialized by primitive types:

  open class Base<T> {
    protected fun foo(x: T) {}
  }

  // in different package
  class Derived : Base<Long> {
    inner class Inner {
      fun bar() { foo(42L) }
    }
  }

Synthetic accessor for 'Base.foo' in 'Derived' has signature '(J)V'
(not '(Ljava.lang.Object;)V' or '(Ljava.lang.Long;)V'),
and should box its parameter.

Note that in Java the corresponding synthetic accessor has signature
'(Ljava.lang.Long;)V' with auto-boxing at call site.

 #KT-20491 Fixed
This commit is contained in:
Dmitry Petrov
2017-09-28 10:32:28 +03:00
parent 73724bcdc7
commit 3994034f46
9 changed files with 168 additions and 8 deletions
@@ -0,0 +1,20 @@
fun box(): String {
A.Nested().nestedA()
A.Nested().Inner().innerA()
A.companionA()
return "OK"
}
class A<T> private constructor(val x: T, val y: Int = 0) {
class Nested {
fun nestedA() = A<Long>(1L)
inner class Inner {
fun innerA() = A<Long>(1L)
}
}
companion object {
fun companionA() = A<Long>(1L)
}
}
@@ -0,0 +1,29 @@
// FILE: test.kt
import b.B
fun box() =
B().getOK()
// FILE: a.kt
package a
open class A<T> {
protected fun getO(x: T) = "O"
protected fun getK(x: T) = "K"
}
// FILE: b.kt
package b
import a.A
class B : A<Long>() {
inner class Inner {
fun innerGetO() = getO(0L)
}
fun lambdaGetK() = { -> getK(0L) }
fun getOK() =
Inner().innerGetO() + lambdaGetK().invoke()
}
@@ -0,0 +1,29 @@
// FILE: test.kt
import b.B
fun box() =
B().getOK()
// FILE: a.kt
package a
open class A<T> {
protected fun getO(x: T, z: String = "") = "O" + z
protected fun getK(x: T, z: String = "") = "K" + z
}
// FILE: b.kt
package b
import a.A
class B : A<Long>() {
inner class Inner {
fun innerGetO() = getO(0L)
}
fun lambdaGetK() = { -> getK(0L) }
fun getOK() =
Inner().innerGetO() + lambdaGetK().invoke()
}