diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index 5f1df4734a4..261a778cc5c 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -51408,6 +51408,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo public void testScriptPropFromAnotherModuleK2() { runTest("compiler/testData/codegen/box/script/scriptPropFromAnotherModuleK2.kt"); } + + @Test + @TestMetadata("syntheticJavaPropertyInScript.kt") + public void testSyntheticJavaPropertyInScript() { + runTest("compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt"); + } } @Nested diff --git a/compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.jvm_abi.txt b/compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.jvm_abi.txt new file mode 100644 index 00000000000..8663276fe66 --- /dev/null +++ b/compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.jvm_abi.txt @@ -0,0 +1,42 @@ +MODULE main + CLASS MainKt.class + Annotation: class.invisibleAnnotations + K1 + @Lkotlin/jvm/internal/SourceDebugExtension;( value: #{ SMAP + main.kt + Kotlin + *S Kotlin + *F + + 1 main.kt + MainKt + + 2 ArrayIntrinsics.kt + kotlin/ArrayIntrinsicsKt + *L + 1#1,50:1 + 26#2:51 + *S KotlinDebug + *F + + 1 main.kt + MainKt + *L + 42#1:51 + *E + } ) + K2 + --- + CLASS Script.class + CLASS METADATA + K1 + ([Ljava/lang/String;)V + K2 + --- + Property: class.metadata.superTypes + K1 + [kotlin/script/templates/standard/ScriptTemplateWithArgs] + K2 + [] + Property: class.metadata.contextReceiverTypes + K1 + [] + K2 + [kotlin/script/templates/standard/ScriptTemplateWithArgs] diff --git a/compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt b/compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt new file mode 100644 index 00000000000..cad1db43d04 --- /dev/null +++ b/compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt @@ -0,0 +1,95 @@ +// TARGET_BACKEND: JVM_IR +// IGNORE_LIGHT_ANALYSIS +// JVM_ABI_K1_K2_DIFF: +// LANGUAGE: +ReferencesToSyntheticJavaProperties +// LANGUAGE: -SkipStandaloneScriptsInSourceRoots +// WITH_STDLIB + +// FILE: J.java + +public class J { + private String stringProperty; + private boolean myBooleanProperty; + public int numGetCalls; + public int numSetCalls; + + public String getStringProperty() { + numGetCalls++; + return stringProperty; + } + + public void setStringProperty(String value) { + numSetCalls++; + stringProperty = value; + } + + public boolean isBooleanProperty() { + numGetCalls++; + return myBooleanProperty; + } + + public void setBooleanProperty(boolean value) { + numSetCalls++; + myBooleanProperty = value; + } +} + +// FILE: main.kt + +fun runScriptMethod(name: String, method: String): Any { + val klass = Thread.currentThread().contextClassLoader.loadClass(name) + val constructor = klass.constructors.single() + val instance = constructor.newInstance(emptyArray()) + val method = klass.getMethod(method) + return method.invoke(instance) +} + +fun box(): String = + runScriptMethod("Script", "f") as String + +// FILE: script.kts + +import kotlin.reflect.* +import kotlin.test.* + +fun f(): String { + val j = J() + + val unboundStringProperty = J::stringProperty + assertNull(unboundStringProperty.get(j)) + unboundStringProperty.set(j, "Hi") + assertEquals("Hi", unboundStringProperty.get(j)) + assertEquals("Hi", unboundStringProperty(j)) + + assertEquals(3, j.numGetCalls) + assertEquals(1, j.numSetCalls) + + val boundStringProperty = j::stringProperty + assertEquals("Hi", boundStringProperty.get()) + boundStringProperty.set("Hello") + assertEquals("Hello", boundStringProperty.get()) + assertEquals("Hello", boundStringProperty()) + + assertEquals(6, j.numGetCalls) + assertEquals(2, j.numSetCalls) + + val unboundBooleanProperty: KMutableProperty1 = J::isBooleanProperty + assertFalse(unboundBooleanProperty.get(j)) + unboundBooleanProperty.set(j, true) + assertTrue(unboundBooleanProperty.get(j)) + assertTrue(unboundBooleanProperty(j)) + + assertEquals(9, j.numGetCalls) + assertEquals(3, j.numSetCalls) + + val boundBooleanProperty: KMutableProperty0 = j::isBooleanProperty + assertTrue(boundBooleanProperty.get()) + boundBooleanProperty.set(false) + assertFalse(boundBooleanProperty.get()) + assertFalse(boundBooleanProperty()) + + assertEquals(12, j.numGetCalls) + assertEquals(4, j.numSetCalls) + + return "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 74e6c5a56f5..aadeaabf54d 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -50718,6 +50718,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testScriptPropFromAnotherModuleK2() { runTest("compiler/testData/codegen/box/script/scriptPropFromAnotherModuleK2.kt"); } + + @Test + @TestMetadata("syntheticJavaPropertyInScript.kt") + public void testSyntheticJavaPropertyInScript() { + runTest("compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt"); + } } @Nested diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 2e4a7aab6d2..327fb6904e4 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -50718,6 +50718,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack public void testScriptPropFromAnotherModuleK2() { runTest("compiler/testData/codegen/box/script/scriptPropFromAnotherModuleK2.kt"); } + + @Test + @TestMetadata("syntheticJavaPropertyInScript.kt") + public void testSyntheticJavaPropertyInScript() { + runTest("compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt"); + } } @Nested diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 323f1690e46..a6c820f4196 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -40766,6 +40766,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testScriptPropFromAnotherModuleK2() { runTest("compiler/testData/codegen/box/script/scriptPropFromAnotherModuleK2.kt"); } + + @TestMetadata("syntheticJavaPropertyInScript.kt") + public void testSyntheticJavaPropertyInScript() { + runTest("compiler/testData/codegen/box/script/syntheticJavaPropertyInScript.kt"); + } } @TestMetadata("compiler/testData/codegen/box/sealed")