JVM_IR: copy correspondingProperty of static external functions
Required for correctly mapping their names. #KT-47715 Fixed
This commit is contained in:
+5
-5
@@ -107,18 +107,18 @@ class JvmCachedDeclarations(
|
|||||||
if (jvmStaticFunction.isExternal) {
|
if (jvmStaticFunction.isExternal) {
|
||||||
// We move external functions to the enclosing class and potentially add accessors there.
|
// 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.
|
// 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 {
|
val staticExternal = context.irFactory.buildFun {
|
||||||
updateFrom(jvmStaticFunction)
|
updateFrom(jvmStaticFunction)
|
||||||
name = jvmStaticFunction.name
|
name = jvmStaticFunction.name
|
||||||
returnType = jvmStaticFunction.returnType
|
returnType = jvmStaticFunction.returnType
|
||||||
}.apply {
|
}.apply {
|
||||||
parent = companion.parent
|
parent = companion.parent
|
||||||
copyTypeParametersFrom(jvmStaticFunction)
|
copyAttributes(jvmStaticFunction)
|
||||||
copyAnnotationsFrom(jvmStaticFunction)
|
copyAnnotationsFrom(jvmStaticFunction)
|
||||||
extensionReceiverParameter = jvmStaticFunction.extensionReceiverParameter?.copyTo(this)
|
copyCorrespondingPropertyFrom(jvmStaticFunction)
|
||||||
valueParameters = jvmStaticFunction.valueParameters.map { it.copyTo(this) }
|
copyParameterDeclarationsFrom(jvmStaticFunction)
|
||||||
|
dispatchReceiverParameter = null
|
||||||
|
metadata = jvmStaticFunction.metadata
|
||||||
}
|
}
|
||||||
staticExternal to companion.makeProxy(staticExternal, isStatic = false)
|
staticExternal to companion.makeProxy(staticExternal, isStatic = false)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+31
-18
@@ -9,31 +9,44 @@ package foo
|
|||||||
class WithNative {
|
class WithNative {
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic external fun bar(l: Long, s: String): Double
|
@JvmStatic external fun bar(l: Long, s: String): Double
|
||||||
|
|
||||||
|
@JvmStatic val prop: String external get
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ObjWithNative {
|
object ObjWithNative {
|
||||||
@JvmStatic external fun bar(l: Long, s: String): Double
|
@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 {
|
fun box(): String {
|
||||||
var d = 0.0
|
check(
|
||||||
try {
|
"foo.WithNative.bar(JLjava/lang/String;)D",
|
||||||
d = WithNative.bar(1, "")
|
"'double foo.WithNative.bar(long, java.lang.String)'"
|
||||||
return "Link error expected"
|
) { WithNative.bar(1, "") }
|
||||||
}
|
check(
|
||||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
"foo.ObjWithNative.bar(JLjava/lang/String;)D",
|
||||||
if (e.message != "foo.WithNative.bar(JLjava/lang/String;)D" &&
|
"'double foo.ObjWithNative.bar(long, java.lang.String)'"
|
||||||
e.message != "'double foo.WithNative.bar(long, java.lang.String)'") return "Fail 1: " + e.message
|
) { ObjWithNative.bar(1, "") }
|
||||||
}
|
check(
|
||||||
|
"foo.WithNative.getProp()Ljava/lang/String;",
|
||||||
try {
|
"'java.lang.String foo.WithNative.getProp()'"
|
||||||
d = ObjWithNative.bar(1, "")
|
) { WithNative.prop }
|
||||||
return "Link error expected on object"
|
check(
|
||||||
}
|
"foo.ObjWithNative.getProp()Ljava/lang/String;",
|
||||||
catch (e: java.lang.UnsatisfiedLinkError) {
|
"'java.lang.String foo.ObjWithNative.getProp()'"
|
||||||
if (e.message != "foo.ObjWithNative.bar(JLjava/lang/String;)D" &&
|
) { ObjWithNative.prop }
|
||||||
e.message != "'double foo.ObjWithNative.bar(long, java.lang.String)'") return "Fail 2: " + e.message
|
|
||||||
}
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user