diff options
author | Steven Schäfer <stevenschaefer@google.com> | 2020-07-08 18:32:53 +0200 |
---|---|---|
committer | Alexander Udalov <udalov@users.noreply.github.com> | 2020-07-13 14:47:28 +0200 |
commit | 12c60d9544d93eb397f907fb3e10d4c2c69dfe93 (patch) | |
tree | ee35b4c289f5b5681081a14567424771103ab258 | |
parent | 9cad15b462756532ab859754a64b396173952f53 (diff) | |
download | kotlin-12c60d9544d93eb397f907fb3e10d4c2c69dfe93.tar.gz |
JVM IR: Mangle delegated properties with inline class type (KT-40125)
(cherry picked from commit 097e0fb46c3b7038e2656795f3f6fd5f5f77c4a7)
4 files changed, 34 insertions, 1 deletions
diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt index 6b6a70d6264..7b118bc18a6 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.backend.jvm.ir.isStaticInlineClassReplacement import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.InlineClassAbi.mangledNameFor import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper import org.jetbrains.kotlin.descriptors.Modality +import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildFunWithDescriptorForInlining @@ -46,7 +47,7 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean) { when { // Don't mangle anonymous or synthetic functions it.origin == IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA || - it.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR || + (it.origin == IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR && it.visibility == Visibilities.LOCAL) || it.isStaticInlineClassReplacement || it.origin.isSynthetic -> null diff --git a/compiler/testData/codegen/bytecodeText/inlineClasses/delegatedPropertyMangling.kt b/compiler/testData/codegen/bytecodeText/inlineClasses/delegatedPropertyMangling.kt new file mode 100644 index 00000000000..d802182aa2e --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/inlineClasses/delegatedPropertyMangling.kt @@ -0,0 +1,22 @@ +// LANGUAGE: +InlineClasses +import kotlin.reflect.KProperty + +inline class I(val x: Int) + +interface A { + val i: I +} + +class Delegate { + operator fun getValue(thisRef: Any?, prop: KProperty<*>): I { + return I(1) + } +} + +class B : A { + override val i by Delegate() +} + +// 1 public final getValue-lPtA-2M\(Ljava/lang/Object;Lkotlin/reflect/KProperty;\)I +// 1 public getI-lPtA-2M\(\)I +// 1 public abstract getI-lPtA-2M\(\)I diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java index c9b16d77e5c..3221c976d29 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeTextTestGenerated.java @@ -2846,6 +2846,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt"); } + @TestMetadata("delegatedPropertyMangling.kt") + public void testDelegatedPropertyMangling() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/delegatedPropertyMangling.kt"); + } + @TestMetadata("equalsDoesNotBox.kt") public void testEqualsDoesNotBox() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/equalsDoesNotBox.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java index 2cf89c80c39..238fcda2255 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeTextTestGenerated.java @@ -2931,6 +2931,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/defaultParametersDontBox.kt"); } + @TestMetadata("delegatedPropertyMangling.kt") + public void testDelegatedPropertyMangling() throws Exception { + runTest("compiler/testData/codegen/bytecodeText/inlineClasses/delegatedPropertyMangling.kt"); + } + @TestMetadata("equalsDoesNotBox.kt") public void testEqualsDoesNotBox() throws Exception { runTest("compiler/testData/codegen/bytecodeText/inlineClasses/equalsDoesNotBox.kt"); |