Take into account JvmName annotation when generating accessors
#KT-17444 Fixed Target versions 1.1.5
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
enum class FieldAccessorKind(val suffix: String) {
|
enum class FieldAccessorKind(val suffix: String) {
|
||||||
NORMAL("p"),
|
NORMAL("p"),
|
||||||
@@ -26,15 +27,18 @@ enum class FieldAccessorKind(val suffix: String) {
|
|||||||
override fun toString() = suffix
|
override fun toString() = suffix
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun CallableMemberDescriptor.getJvmName() =
|
||||||
|
DescriptorUtils.getJvmName(this) ?: name.asString()
|
||||||
|
|
||||||
fun getAccessorNameSuffix(descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?,
|
fun getAccessorNameSuffix(descriptor: CallableMemberDescriptor, superCallDescriptor: ClassDescriptor?,
|
||||||
accessorKind: FieldAccessorKind): String {
|
accessorKind: FieldAccessorKind): String {
|
||||||
val suffix = when (descriptor) {
|
val suffix = when (descriptor) {
|
||||||
is ConstructorDescriptor ->
|
is ConstructorDescriptor ->
|
||||||
return "will be ignored"
|
return "will be ignored"
|
||||||
is SimpleFunctionDescriptor ->
|
is SimpleFunctionDescriptor ->
|
||||||
descriptor.name.asString()
|
descriptor.getJvmName()
|
||||||
is PropertyDescriptor ->
|
is PropertyDescriptor ->
|
||||||
descriptor.name.asString() + "$" + accessorKind
|
descriptor.getJvmName() + "$" + accessorKind
|
||||||
else ->
|
else ->
|
||||||
throw UnsupportedOperationException("Do not know how to create accessor for descriptor " + descriptor)
|
throw UnsupportedOperationException("Do not know how to create accessor for descriptor " + descriptor)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
// IGNORE_BACKEND: JS, NATIVE
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
|
||||||
|
@JvmName("fooA")
|
||||||
|
private fun String.foo(t: String?): String = this
|
||||||
|
|
||||||
|
private fun String.foo(t: String): String = this
|
||||||
|
|
||||||
|
fun runNoInline(fn: () -> String) = fn()
|
||||||
|
|
||||||
|
fun box() =
|
||||||
|
runNoInline { "O".foo("") } +
|
||||||
|
runNoInline { "K".foo(null) }
|
||||||
|
|
||||||
+6
@@ -18029,6 +18029,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmNameForAccessors.kt")
|
||||||
|
public void testJvmNameForAccessors() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt10047.kt")
|
@TestMetadata("kt10047.kt")
|
||||||
public void testKt10047() throws Exception {
|
public void testKt10047() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
||||||
|
|||||||
@@ -18029,6 +18029,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmNameForAccessors.kt")
|
||||||
|
public void testJvmNameForAccessors() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt10047.kt")
|
@TestMetadata("kt10047.kt")
|
||||||
public void testKt10047() throws Exception {
|
public void testKt10047() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
||||||
|
|||||||
@@ -18029,6 +18029,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmNameForAccessors.kt")
|
||||||
|
public void testJvmNameForAccessors() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt10047.kt")
|
@TestMetadata("kt10047.kt")
|
||||||
public void testKt10047() throws Exception {
|
public void testKt10047() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
||||||
|
|||||||
+12
@@ -22103,6 +22103,18 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/syntheticAccessors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmNameForAccessors.kt")
|
||||||
|
public void testJvmNameForAccessors() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/jvmNameForAccessors.kt");
|
||||||
|
try {
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
catch (Throwable ignore) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt10047.kt")
|
@TestMetadata("kt10047.kt")
|
||||||
public void testKt10047() throws Exception {
|
public void testKt10047() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/syntheticAccessors/kt10047.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user