From e4480a1c524bf1d57f7e96f4ca519e669f8f7fc6 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Thu, 13 Apr 2023 14:31:50 +0200 Subject: [PATCH] K2: Refine mapping of primitive arrays to JVM descriptor Earlier, it wasn't really important but after the previous commit when JvmMappedScope semantics has been changed, we erroneously started loading `toCharArray` as a member to String because its jvmDescriptor was computed to "toCharArray()Lkotlin/CharArray", while hardcoded information that prevents it from loading expect "toCharArray()[C" there. ^KT-57694 In progress --- .../FirLightTreeBlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/FirPsiBlackBoxCodegenTestGenerated.java | 6 ++++++ .../jetbrains/kotlin/fir/scopes/jvm/SignatureUtils.kt | 9 ++++++++- compiler/testData/codegen/box/jdk/noStringToCharArray.kt | 4 ++++ .../runners/codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../runners/codegen/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../IrBlackBoxCodegenWithIrInlinerTestGenerated.java | 6 ++++++ .../kotlin/codegen/LightAnalysisModeTestGenerated.java | 5 +++++ .../kotlin/js/test/JsCodegenBoxTestGenerated.java | 6 ++++++ .../kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java | 6 ++++++ .../kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java | 6 ++++++ .../js/test/ir/IrJsES6CodegenBoxTestGenerated.java | 6 ++++++ .../blackboxtest/FirNativeCodegenBoxTestGenerated.java | 6 ++++++ .../FirNativeCodegenBoxTestNoPLGenerated.java | 6 ++++++ .../blackboxtest/NativeCodegenBoxTestGenerated.java | 6 ++++++ .../blackboxtest/NativeCodegenBoxTestNoPLGenerated.java | 6 ++++++ .../kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java | 5 +++++ 17 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/jdk/noStringToCharArray.kt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index e9aae1ead27..488cdf21fb9 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -29921,6 +29921,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } + @Test @TestMetadata("removeIf.kt") public void testRemoveIf() throws Exception { 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 4a488c88004..d2502c19f5b 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 @@ -29921,6 +29921,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } + @Test @TestMetadata("removeIf.kt") public void testRemoveIf() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/SignatureUtils.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/SignatureUtils.kt index f46dcda9701..c121517ad6b 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/SignatureUtils.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/scopes/jvm/SignatureUtils.kt @@ -69,6 +69,13 @@ private val PRIMITIVE_TYPE_SIGNATURE: Map = mapOf( "Double" to "D", ) +private val PRIMITIVE_TYPE_ARRAYS_SIGNATURE: Map = + PRIMITIVE_TYPE_SIGNATURE.map { (name, desc) -> + "${name}Array" to "[$desc" + }.toMap() + +private val PRIMITIVE_TYPE_OR_ARRAY_SIGNATURE: Map = PRIMITIVE_TYPE_SIGNATURE + PRIMITIVE_TYPE_ARRAYS_SIGNATURE + fun ConeKotlinType.computeJvmDescriptorRepresentation( typeConversion: (FirTypeRef) -> ConeKotlinType? = FirTypeRef::coneTypeSafe ): String = buildString { @@ -82,7 +89,7 @@ private fun StringBuilder.appendConeType( (coneType as? ConeClassLikeType)?.let { val classId = it.lookupTag.classId if (classId.packageFqName.toString() == "kotlin") { - PRIMITIVE_TYPE_SIGNATURE[classId.shortClassName.identifier]?.let { signature -> + PRIMITIVE_TYPE_OR_ARRAY_SIGNATURE[classId.shortClassName.identifier]?.let { signature -> append(signature) return } diff --git a/compiler/testData/codegen/box/jdk/noStringToCharArray.kt b/compiler/testData/codegen/box/jdk/noStringToCharArray.kt new file mode 100644 index 00000000000..f84f2d5c7fe --- /dev/null +++ b/compiler/testData/codegen/box/jdk/noStringToCharArray.kt @@ -0,0 +1,4 @@ +// WITH_STDLIB +internal val wildcardChars = "OK".toCharArray() + +fun box(): String = "${wildcardChars[0]}${wildcardChars[1]}" diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index a5ed12a3662..b1e4e7df33e 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -28445,6 +28445,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } + @Test @TestMetadata("removeIf.kt") public void testRemoveIf() throws Exception { 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 258bf3619f2..441c1a6da45 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 @@ -29921,6 +29921,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } + @Test @TestMetadata("removeIf.kt") public void testRemoveIf() throws Exception { 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 77b3e2fc988..a4d24ac3048 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 @@ -29921,6 +29921,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } + @Test @TestMetadata("removeIf.kt") public void testRemoveIf() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 337cca782e4..7e73314e85b 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -24093,6 +24093,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } + @TestMetadata("removeIf.kt") public void testRemoveIf() throws Exception { runTest("compiler/testData/codegen/box/jdk/removeIf.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 1439c12ebb3..152f1f3b38a 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -21718,6 +21718,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java index 467c254175f..e9fdb6e13d9 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirJsCodegenBoxTestGenerated.java @@ -21868,6 +21868,12 @@ public class FirJsCodegenBoxTestGenerated extends AbstractFirJsCodegenBoxTest { public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index cb630b78f39..f0baf97d346 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -21868,6 +21868,12 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java index 2dd8b9e9861..5049beb7816 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsES6CodegenBoxTestGenerated.java @@ -21868,6 +21868,12 @@ public class IrJsES6CodegenBoxTestGenerated extends AbstractIrJsES6CodegenBoxTes public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java index 3d572b8d462..95dd63e919b 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestGenerated.java @@ -24826,6 +24826,12 @@ public class FirNativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTe public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java index c09a2c5ef98..3ed9d86995f 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeCodegenBoxTestNoPLGenerated.java @@ -25336,6 +25336,12 @@ public class FirNativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenB public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index 7a6c89406d7..20d2b4c67ea 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -24572,6 +24572,12 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java index 303c8ade2a2..f1f2b43819a 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestNoPLGenerated.java @@ -24827,6 +24827,12 @@ public class NativeCodegenBoxTestNoPLGenerated extends AbstractNativeCodegenBoxT public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @Test + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @Nested diff --git a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java index 5c40d0f482c..732938e060b 100644 --- a/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java +++ b/wasm/wasm.tests/tests-gen/org/jetbrains/kotlin/wasm/test/IrCodegenBoxWasmTestGenerated.java @@ -19320,6 +19320,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest public void testKt1397() throws Exception { runTest("compiler/testData/codegen/box/jdk/kt1397.kt"); } + + @TestMetadata("noStringToCharArray.kt") + public void testNoStringToCharArray() throws Exception { + runTest("compiler/testData/codegen/box/jdk/noStringToCharArray.kt"); + } } @TestMetadata("compiler/testData/codegen/box/js")