Generate property initializer within property scope

This commit is contained in:
Dmitry Petrov
2017-05-04 14:09:12 +03:00
parent 8e84862afa
commit ddb2b7508b
4 changed files with 24 additions and 4 deletions
@@ -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 =
@@ -0,0 +1 @@
val test = try { } catch (e : Throwable) { }
@@ -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 <get-test>(): kotlin.Unit
BLOCK_BODY
RETURN type=kotlin.Nothing from='<get-test>(): Unit'
GET_FIELD 'test: Unit' type=kotlin.Unit origin=null
@@ -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");