diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt index deedca17b8d..b9ac0f722ab 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt @@ -97,8 +97,8 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED, false, propertyDescriptor - ).apply { - backingField = + ).buildWithScope { irProperty -> + irProperty.backingField = if (propertyDescriptor.hasBackingField()) generatePropertyBackingField(ktProperty, propertyDescriptor) { irField -> ktProperty.initializer?.let { ktInitializer -> @@ -108,9 +108,9 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio else null - getter = generateGetterIfRequired(ktProperty, propertyDescriptor) + irProperty.getter = generateGetterIfRequired(ktProperty, propertyDescriptor) - setter = generateSetterIfRequired(ktProperty, propertyDescriptor) + irProperty.setter = generateSetterIfRequired(ktProperty, propertyDescriptor) } private fun PropertyDescriptor.hasBackingField(): Boolean = diff --git a/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.kt b/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.kt new file mode 100644 index 00000000000..b0b732e0923 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.kt @@ -0,0 +1 @@ +val test = try { } catch (e : Throwable) { } \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.txt b/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.txt new file mode 100644 index 00000000000..593e46e6e14 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.txt @@ -0,0 +1,13 @@ +FILE /catchParameterInTopLevelProperty.kt + PROPERTY public val test: kotlin.Unit + FIELD PROPERTY_BACKING_FIELD public val test: kotlin.Unit + EXPRESSION_BODY + TRY type=kotlin.Unit + try: BLOCK type=kotlin.Unit origin=null + CATCH parameter=e: Throwable + VAR CATCH_PARAMETER val e: kotlin.Throwable + BLOCK type=kotlin.Unit origin=null + FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Unit' + GET_FIELD 'test: Unit' type=kotlin.Unit origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index 83d2c94fb96..52633dc4a73 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -227,6 +227,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/ir/irText/declarations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("catchParameterInTopLevelProperty.kt") + public void testCatchParameterInTopLevelProperty() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/catchParameterInTopLevelProperty.kt"); + doTest(fileName); + } + @TestMetadata("classLevelProperties.kt") public void testClassLevelProperties() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/classLevelProperties.kt");