JVM_IR: copy correspondingProperty of static external functions

Required for correctly mapping their names.

 #KT-47715 Fixed
This commit is contained in:
pyos
2021-07-14 11:47:22 +02:00
committed by Alexander Udalov
parent adeb2f527b
commit ad7ed483f3
2 changed files with 36 additions and 23 deletions
@@ -107,18 +107,18 @@ class JvmCachedDeclarations(
if (jvmStaticFunction.isExternal) {
// We move external functions to the enclosing class and potentially add accessors there.
// The JVM backend also adds accessors in the companion object, but these are superfluous.
// TODO: this should really do the same as `makeProxy`, but without a body; otherwise, external
// functions in interface companions won't work (KT-43696).
val staticExternal = context.irFactory.buildFun {
updateFrom(jvmStaticFunction)
name = jvmStaticFunction.name
returnType = jvmStaticFunction.returnType
}.apply {
parent = companion.parent
copyTypeParametersFrom(jvmStaticFunction)
copyAttributes(jvmStaticFunction)
copyAnnotationsFrom(jvmStaticFunction)
extensionReceiverParameter = jvmStaticFunction.extensionReceiverParameter?.copyTo(this)
valueParameters = jvmStaticFunction.valueParameters.map { it.copyTo(this) }
copyCorrespondingPropertyFrom(jvmStaticFunction)
copyParameterDeclarationsFrom(jvmStaticFunction)
dispatchReceiverParameter = null
metadata = jvmStaticFunction.metadata
}
staticExternal to companion.makeProxy(staticExternal, isStatic = false)
} else {
+31 -18
View File
@@ -9,31 +9,44 @@ package foo
class WithNative {
companion object {
@JvmStatic external fun bar(l: Long, s: String): Double
@JvmStatic val prop: String external get
}
}
object ObjWithNative {
@JvmStatic external fun bar(l: Long, s: String): Double
@JvmStatic val prop: String external get
}
fun check(vararg allowed: String, block: () -> Unit) {
try {
block()
throw AssertionError("UnsatisfiedLinkError expected")
} catch (e: java.lang.UnsatisfiedLinkError) {
if (allowed.none { it == e.message }) {
throw AssertionError("fail: ${e.message}")
}
}
}
fun box(): String {
var d = 0.0
try {
d = WithNative.bar(1, "")
return "Link error expected"
}
catch (e: java.lang.UnsatisfiedLinkError) {
if (e.message != "foo.WithNative.bar(JLjava/lang/String;)D" &&
e.message != "'double foo.WithNative.bar(long, java.lang.String)'") return "Fail 1: " + e.message
}
try {
d = ObjWithNative.bar(1, "")
return "Link error expected on object"
}
catch (e: java.lang.UnsatisfiedLinkError) {
if (e.message != "foo.ObjWithNative.bar(JLjava/lang/String;)D" &&
e.message != "'double foo.ObjWithNative.bar(long, java.lang.String)'") return "Fail 2: " + e.message
}
check(
"foo.WithNative.bar(JLjava/lang/String;)D",
"'double foo.WithNative.bar(long, java.lang.String)'"
) { WithNative.bar(1, "") }
check(
"foo.ObjWithNative.bar(JLjava/lang/String;)D",
"'double foo.ObjWithNative.bar(long, java.lang.String)'"
) { ObjWithNative.bar(1, "") }
check(
"foo.WithNative.getProp()Ljava/lang/String;",
"'java.lang.String foo.WithNative.getProp()'"
) { WithNative.prop }
check(
"foo.ObjWithNative.getProp()Ljava/lang/String;",
"'java.lang.String foo.ObjWithNative.getProp()'"
) { ObjWithNative.prop }
return "OK"
}