From e5dce9f994c3c9233b1148a51d4349d045086308 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Wed, 25 Nov 2020 13:39:15 +0300 Subject: [PATCH] KT-42933 inline class backing field can't be static --- .../codegen/ir/FirBlackBoxCodegenTestGenerated.java | 5 +++++ .../org/jetbrains/kotlin/ir/util/InlineClasses.kt | 10 +++++++--- .../box/inlineClasses/propertyDelegation/kt42933.kt | 12 ++++++++++++ .../kotlin/codegen/BlackBoxCodegenTestGenerated.java | 5 +++++ .../codegen/LightAnalysisModeTestGenerated.java | 5 +++++ .../codegen/ir/IrBlackBoxCodegenTestGenerated.java | 5 +++++ .../semantics/IrJsCodegenBoxES6TestGenerated.java | 5 +++++ .../ir/semantics/IrJsCodegenBoxTestGenerated.java | 5 +++++ .../js/test/semantics/JsCodegenBoxTestGenerated.java | 5 +++++ .../semantics/IrCodegenBoxWasmTestGenerated.java | 5 +++++ 10 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 378ef87901b..3336d040de2 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -15155,6 +15155,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt index 9452afa3261..ed569d322ac 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/InlineClasses.kt @@ -69,11 +69,15 @@ fun getInlineClassUnderlyingType(irClass: IrClass): IrType { fun getInlineClassBackingField(irClass: IrClass): IrField { for (declaration in irClass.declarations) { - if (declaration is IrField) + if (declaration is IrField && !declaration.isStatic) return declaration - if (declaration is IrProperty) - return declaration.backingField ?: continue + if (declaration is IrProperty) { + val backingField = declaration.backingField + if (backingField != null && !backingField.isStatic) { + return backingField + } + } } error("Inline class has no field: ${irClass.fqNameWhenAvailable}") } diff --git a/compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt b/compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt new file mode 100644 index 00000000000..29c5328bd16 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt @@ -0,0 +1,12 @@ +class Delegate { + operator fun getValue(t: Any?, p: Any): String = "OK" +} + +inline class Kla1(val default: Int) { + fun getValue(): String { + val prop by Delegate() + return prop + } +} + +fun box() = Kla1(1).getValue() \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 442ecc7ec94..0b527485966 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16555,6 +16555,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index beb97d7683d..a3e551d817e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16555,6 +16555,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index ed92a8e0f66..01c6f247826 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -15155,6 +15155,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index ea0a206b712..29c99181d5e 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -13125,6 +13125,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 76205ae7973..3be1ff3e341 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -13125,6 +13125,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 622042f2b57..fef08948512 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -13190,6 +13190,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { public void testKt27070() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt27070.kt"); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter") diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 86efc618ee6..b1654e02dd5 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -7440,6 +7440,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest public void testAllFilesPresentInPropertyDelegation() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/inlineClasses/propertyDelegation"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); } + + @TestMetadata("kt42933.kt") + public void testKt42933() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/propertyDelegation/kt42933.kt"); + } } @TestMetadata("compiler/testData/codegen/box/inlineClasses/unboxGenericParameter")