From b1643075f276efdcf05fe98b8773e2ccf4afeb73 Mon Sep 17 00:00:00 2001 From: Artem Kobzar Date: Thu, 9 Dec 2021 13:39:35 +0000 Subject: [PATCH] fix(KT-50040): remove the corresponding symbol from top-level accessors. --- .../js/lower/PrivateMembersLowering.kt | 1 - .../kotlin/js/test/BoxJsTestGenerated.java | 6 ++++++ .../js/test/ir/IrBoxJsTestGenerated.java | 6 ++++++ .../privatePropertyAccessFromMethod.kt | 20 +++++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 js/js.translator/testData/box/jsExport/privatePropertyAccessFromMethod.kt diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrivateMembersLowering.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrivateMembersLowering.kt index 24a4e23eda2..109bc03adab 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrivateMembersLowering.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/PrivateMembersLowering.kt @@ -59,7 +59,6 @@ class PrivateMembersLowering(val context: JsIrBackendContext) : DeclarationTrans visibility = newVisibility }.also { it.parent = function.parent - it.correspondingPropertySymbol = function.correspondingPropertySymbol } staticFunction.typeParameters += function.typeParameters.map { it.deepCopyWithSymbols(staticFunction) } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java index 254dbd3f635..f254474c8e9 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/BoxJsTestGenerated.java @@ -6256,6 +6256,12 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/jsExport/jsExportInClass.kt"); } + @Test + @TestMetadata("privatePropertyAccessFromMethod.kt") + public void testPrivatePropertyAccessFromMethod() throws Exception { + runTest("js/js.translator/testData/box/jsExport/privatePropertyAccessFromMethod.kt"); + } + @Test @TestMetadata("recursiveExport.kt") public void testRecursiveExport() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java index b022e8adb55..507dec73fdc 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrBoxJsTestGenerated.java @@ -6640,6 +6640,12 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/jsExport/jsExportInClass.kt"); } + @Test + @TestMetadata("privatePropertyAccessFromMethod.kt") + public void testPrivatePropertyAccessFromMethod() throws Exception { + runTest("js/js.translator/testData/box/jsExport/privatePropertyAccessFromMethod.kt"); + } + @Test @TestMetadata("recursiveExport.kt") public void testRecursiveExport() throws Exception { diff --git a/js/js.translator/testData/box/jsExport/privatePropertyAccessFromMethod.kt b/js/js.translator/testData/box/jsExport/privatePropertyAccessFromMethod.kt new file mode 100644 index 00000000000..6fcb87bbdc4 --- /dev/null +++ b/js/js.translator/testData/box/jsExport/privatePropertyAccessFromMethod.kt @@ -0,0 +1,20 @@ +// EXPECTED_REACHABLE_NODES: 1286 +// TARGET_BACKENDS=JS_IR + +package foo + +@JsExport +object A { + private val foo: Int + get() = 23 + + fun bar(): Int { + return foo + } +} + +fun box(): String { + var result = A.bar() + if (result != 23) return "failed: ${result}" + return "OK" +}