JVM_IR: Fix default argument bit mask for methods made static.

When called by reflection the bit mask will be generated
discounting dispatch/extension receivers. Make sure that the
interpretation of the bit mask is consistent for direct and
reflective calls.

In addition, this also fixes the modifiers on java 8 parameter
metadata for the dispatch and extension receivers for these
inline class methods.
This commit is contained in:
Mads Ager
2020-01-03 11:28:43 +01:00
committed by max-kammerer
parent 137c500e3a
commit 1ed7e33f42
12 changed files with 126 additions and 10 deletions
@@ -0,0 +1,29 @@
// IGNORE_BACKEND_FIR: JVM_IR
// SKIP_JDK6
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FULL_JDK
// KOTLIN_CONFIGURATION_FLAGS: +JVM.PARAMETERS_METADATA
// FILE: A.kt
inline class A(val i: Int) {
fun f() = i
}
fun A.extension() = this.i
fun box(): String {
val method = Class.forName("A").declaredMethods.single { it.name == "f-impl" }
val parameters = method.getParameters()
if (!parameters[0].isSynthetic()) return "wrong modifier on receiver parameter: ${parameters[0].modifiers}"
val extensionMethod = Class.forName("AKt").declaredMethods.single { it.name.contains("extension") }
val extensionMethodParameters = extensionMethod.getParameters()
if (extensionMethodParameters[0].isSynthetic())
return "wrong modifier (synthetic) on extension receiver parameter: ${extensionMethodParameters[0].modifiers}"
if (!extensionMethodParameters[0].isImplicit())
return "wrong modifier (not implicit) on extension receiver parameter: ${extensionMethodParameters[0].modifiers}"
return "OK"
}
@@ -0,0 +1,28 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM_IR
// SKIP_JDK6
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FULL_JDK
// KOTLIN_CONFIGURATION_FLAGS: +JVM.PARAMETERS_METADATA
// FILE: A.kt
inline class A(val i: Int) {
fun f() = i
}
fun A.extension() = this.i
fun box(): String {
val method = Class.forName("A").declaredMethods.single { it.name == "f-impl" }
val parameters = method.getParameters()
if (parameters[0].name != "arg0") return "wrong name on receiver parameter: ${parameters[0].name}"
val extensionMethod = Class.forName("AKt").declaredMethods.single { it.name.contains("extension") }
val extensionMethodParameters = extensionMethod.getParameters()
if (extensionMethodParameters[0].name != "\$this\$extension")
return "wrong name on extension receiver parameter: ${extensionMethodParameters[0].name}"
return "OK"
}
@@ -1,5 +1,5 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JS_IR, JS, NATIVE, JVM_IR
// IGNORE_BACKEND: JS_IR, JS, NATIVE
// WITH_REFLECT
import kotlin.test.assertEquals
@@ -23,17 +23,19 @@ class D(e: S, f: S = S("f")) {
fun S.extension(h: S = S("h")): S = this + h
fun box(): String {
assertEquals(S("ab"), C().member(S("a")))
assertEquals(S("ab"), C::member.callBy(C::member.parameters.filter { it.name != "b" }.associate {
it to (if (it.name == "a") S("a") else C())
}))
assertEquals(S("cd"), topLevel(S("c")))
assertEquals(S("cd"), ::topLevel.callBy(::topLevel.parameters.filter { it.name != "d" }.associate { it to S("c") }))
// assertEquals(S("ef"), ::D.callBy(::D.parameters.filter { it.name != "f" }.associate { it to S("e") }).result)
assertEquals(S("gh"), S("g").extension())
assertEquals(S("gh"), S::extension.callBy(S::extension.parameters.filter { it.name != "h" }.associate { it to S("g") }))
val boundMember = C()::member
assertEquals(S("ab"), boundMember.callBy(boundMember.parameters.associate { it to S(it.name!!) }))