JVM_IR: keep the $default suffix for stubs for @JvmName functions
Technically a backwards compatibility problem, as the new backend
*consistently* renamed `f$default` on `f` with `@JvmName("g")` to
`g` instead of `g$default`, so it all worked out. However, this
breaks when encountering libraries compiled with the non-IR backend.
This commit is contained in:
@@ -85,8 +85,10 @@ val IrType.erasedUpperBound: IrClass
|
|||||||
|
|
||||||
|
|
||||||
fun IrDeclaration.getJvmNameFromAnnotation(): String? {
|
fun IrDeclaration.getJvmNameFromAnnotation(): String? {
|
||||||
val const = getAnnotation(DescriptorUtils.JVM_NAME)?.getValueArgument(0) as? IrConst<*>
|
// TODO lower @JvmName?
|
||||||
return const?.value as? String
|
val const = getAnnotation(DescriptorUtils.JVM_NAME)?.getValueArgument(0) as? IrConst<*> ?: return null
|
||||||
|
val value = const.value as? String ?: return null
|
||||||
|
return if (origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER) "$value\$default" else value
|
||||||
}
|
}
|
||||||
|
|
||||||
val IrFunction.propertyIfAccessor: IrDeclaration
|
val IrFunction.propertyIfAccessor: IrDeclaration
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
@JvmName("bar")
|
||||||
|
fun foo(x: String = (object {}).javaClass.enclosingMethod.name) = x
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val f = foo()
|
||||||
|
if (f != "bar\$default") return "Fail: $f"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+5
@@ -15091,6 +15091,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
|
runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionWithDefault.kt")
|
||||||
|
public void testFunctionWithDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmName/functionWithDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("loadJvmName.kt")
|
@TestMetadata("loadJvmName.kt")
|
||||||
public void testLoadJvmName() throws Exception {
|
public void testLoadJvmName() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");
|
runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");
|
||||||
|
|||||||
+5
@@ -15091,6 +15091,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
|
runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionWithDefault.kt")
|
||||||
|
public void testFunctionWithDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmName/functionWithDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("loadJvmName.kt")
|
@TestMetadata("loadJvmName.kt")
|
||||||
public void testLoadJvmName() throws Exception {
|
public void testLoadJvmName() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");
|
runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");
|
||||||
|
|||||||
+5
@@ -13976,6 +13976,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
|
runTest("compiler/testData/codegen/box/jvmName/functionName.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionWithDefault.kt")
|
||||||
|
public void testFunctionWithDefault() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/jvmName/functionWithDefault.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("loadJvmName.kt")
|
@TestMetadata("loadJvmName.kt")
|
||||||
public void testLoadJvmName() throws Exception {
|
public void testLoadJvmName() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");
|
runTest("compiler/testData/codegen/box/jvmName/loadJvmName.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user