JVM_IR. Don't copy synthetic method for property annotations if @JvmStatic presented
This commit is contained in:
+2
-1
@@ -251,5 +251,6 @@ private class MakeCallsStatic(
|
||||
private fun isJvmStaticFunction(declaration: IrDeclaration): Boolean =
|
||||
declaration is IrSimpleFunction &&
|
||||
(declaration.hasAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) ||
|
||||
declaration.correspondingPropertySymbol?.owner?.hasAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) == true)
|
||||
declaration.correspondingPropertySymbol?.owner?.hasAnnotation(JVM_STATIC_ANNOTATION_FQ_NAME) == true) &&
|
||||
declaration.origin != JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS
|
||||
|
||||
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
// !LANGUAGE: +UseGetterNameForPropertyAnnotationsMethodOnJvm
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
// FULL_JDK
|
||||
// JVM_TARGET: 1.8
|
||||
|
||||
package test
|
||||
|
||||
import java.lang.reflect.Modifier
|
||||
import kotlin.test.*
|
||||
|
||||
class WithCompanionJvmStatic {
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val property: Int
|
||||
get() = 42
|
||||
}
|
||||
}
|
||||
|
||||
interface InterfaceWithCompanionJvmStatic {
|
||||
|
||||
fun defaultImplsTrigger() = 123
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
val property: Int
|
||||
get() = 42
|
||||
}
|
||||
}
|
||||
|
||||
fun check(clazz: Class<*>, expected: Boolean = true) {
|
||||
for (method in clazz.getDeclaredMethods()) {
|
||||
if (method.getName() == "getProperty\$annotations") {
|
||||
if (!expected) {
|
||||
fail("Synthetic method for annotated property found, but not expected: $method")
|
||||
}
|
||||
assertTrue(method.isSynthetic())
|
||||
assertTrue(Modifier.isStatic(method.modifiers))
|
||||
assertTrue(Modifier.isPublic(method.modifiers))
|
||||
val str = method.declaredAnnotations.single().toString()
|
||||
assertTrue("@kotlin.jvm.JvmStatic\\(\\)".toRegex().matches(str), str)
|
||||
return
|
||||
}
|
||||
}
|
||||
if (expected) {
|
||||
fail("Synthetic method for annotated property expected, but not found")
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
check(Class.forName("test.WithCompanionJvmStatic"), expected = false)
|
||||
check(Class.forName("test.WithCompanionJvmStatic\$Companion"))
|
||||
|
||||
check(Class.forName("test.InterfaceWithCompanionJvmStatic"), expected = false)
|
||||
check(Class.forName("test.InterfaceWithCompanionJvmStatic\$DefaultImpls"), expected = false)
|
||||
check(Class.forName("test.InterfaceWithCompanionJvmStatic\$Companion"))
|
||||
|
||||
return "OK"
|
||||
}
|
||||
+5
@@ -186,6 +186,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForJvmStaticProperty.kt")
|
||||
public void testSyntheticMethodForJvmStaticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForProperty.kt")
|
||||
public void testSyntheticMethodForProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||
|
||||
+5
@@ -191,6 +191,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForJvmStaticProperty.kt")
|
||||
public void testSyntheticMethodForJvmStaticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForProperty.kt")
|
||||
public void testSyntheticMethodForProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||
|
||||
+5
@@ -186,6 +186,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForJvmStaticProperty.kt")
|
||||
public void testSyntheticMethodForJvmStaticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForProperty.kt")
|
||||
public void testSyntheticMethodForProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||
|
||||
+5
@@ -186,6 +186,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForJvmStaticProperty.kt")
|
||||
public void testSyntheticMethodForJvmStaticProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForJvmStaticProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("syntheticMethodForProperty.kt")
|
||||
public void testSyntheticMethodForProperty() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/annotations/syntheticMethodForProperty.kt");
|
||||
|
||||
Reference in New Issue
Block a user