Fix inlining of functions with matching JVM signatures in same package

When two functions with matching JVM signatures in the same package
were inlined sequentially, inliner could take a wrong method body from
the cache due to MethodId clash. This manifested with inline classes,
but also was possible with some legal Kotlin overloads with matching
erasure.

Use internal name of the corresponding implementation owner class
instead of FQN of the containing declaration. Such MethodIds can't match
accidentally, because corresponding JVM method signatures would clash.
This commit is contained in:
Dmitry Petrov
2018-08-20 11:47:30 +03:00
parent f9bba3ca86
commit b5f37d18b2
8 changed files with 125 additions and 60 deletions
@@ -0,0 +1,3 @@
package lib
inline fun Int.toString(ignored: Int) = toString()
@@ -0,0 +1,5 @@
package lib
inline class J(val value: Int)
inline fun J.toString(ignored: Int) = "J$value"
@@ -0,0 +1,11 @@
warning: ATTENTION!
This build uses unsafe internal compiler arguments:
-XXLanguage:+InlineClasses
This mode is not recommended for production use,
as no stability/compatibility guarantees are given on
compiler or generated code. Use it at your own risk!
warning: following manually enabled features will force generation of pre-release binaries: InlineClasses
OK
@@ -0,0 +1,8 @@
import lib.*
fun run() {
val test1 = 42.toString(10)
val test2 = J(42).toString(10)
if (test1 != "42") throw AssertionError(test1)
if (test2 != "J42") throw AssertionError(test2)
}