From f2c734fc0210ee23bbaed767c890f6b26c3c8e86 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 1 Nov 2021 19:04:00 +0300 Subject: [PATCH] FIR2IR: add another fallback for simple synthetic property --- .../fir/backend/Fir2IrDeclarationStorage.kt | 4 +++- .../FirBlackBoxCodegenTestGenerated.java | 6 +++++ .../codegen/box/fir/ColorValuePanel.kt | 23 +++++++++++++++++++ .../IrBlackBoxCodegenTestGenerated.java | 6 +++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/fir/ColorValuePanel.kt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 942b46abd4b..b9b2edf185b 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -1171,7 +1171,9 @@ class Fir2IrDeclarationStorage( dispatchReceiverIrClass.declarations.find { it is IrSimpleFunction && it.isFakeOverride && it.name == fir.name && it.overrides(originalSymbol.owner as IrSimpleFunction) - }?.symbol as IrFunctionSymbol + }?.symbol as? IrFunctionSymbol + // Fallback for simple synthetic property + ?: originalSymbol } else { originalSymbol } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 6b73e020b60..8e737758c42 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -16336,6 +16336,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("ColorValuePanel.kt") + public void testColorValuePanel() throws Exception { + runTest("compiler/testData/codegen/box/fir/ColorValuePanel.kt"); + } + @Test @TestMetadata("ConstValAccess.kt") public void testConstValAccess() throws Exception { diff --git a/compiler/testData/codegen/box/fir/ColorValuePanel.kt b/compiler/testData/codegen/box/fir/ColorValuePanel.kt new file mode 100644 index 00000000000..b0e9a540bc0 --- /dev/null +++ b/compiler/testData/codegen/box/fir/ColorValuePanel.kt @@ -0,0 +1,23 @@ +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND: ANDROID, ANDROID_IR +// WITH_RUNTIME +// FULL_JDK + +import java.awt.GridLayout +import javax.swing.JPanel + +class Some { + val baz get() = foo().layout + + companion object { + private fun foo() = object : ButtonPanel() { + init { + layout = GridLayout() + } + } + } +} + +abstract class ButtonPanel : JPanel() + +fun box() = if (Some().baz is GridLayout) "OK" else "FAIL" 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 df112710317..abbb4c2138f 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 @@ -16336,6 +16336,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/fir/classCanNotBeCastedToVoid.kt"); } + @Test + @TestMetadata("ColorValuePanel.kt") + public void testColorValuePanel() throws Exception { + runTest("compiler/testData/codegen/box/fir/ColorValuePanel.kt"); + } + @Test @TestMetadata("ConstValAccess.kt") public void testConstValAccess() throws Exception {