From 8b395589beabb7713bc1bfaa6a88c4092d37250a Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 6 Feb 2019 16:05:50 +0100 Subject: [PATCH] JVM IR: fix incorrect IR types in inner and enum class lowerings In InnerClassesLowering, the type of the "outer$0" expression should be the outer class, not the inner class. In EnumClassLowering, the type of the enum entry is the type of its class or the type of the enum class, but not the type of initialierExpression which is always Unit --- .../kotlin/backend/common/lower/InnerClassesLowering.kt | 9 +-------- .../kotlin/backend/jvm/lower/EnumClassLowering.kt | 7 ++++--- compiler/testData/codegen/box/classes/kt2566_2.kt | 1 - .../testData/codegen/box/super/innerClassLabeledSuper.kt | 1 - 4 files changed, 5 insertions(+), 13 deletions(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt index 0be13f545e6..1bbb5938b52 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/InnerClassesLowering.kt @@ -141,14 +141,7 @@ class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass { } val outerThisField = context.declarationFactory.getOuterThisField(innerClass) - irThis = IrGetFieldImpl( - startOffset, - endOffset, - outerThisField.symbol, - innerClass.defaultType, - irThis, - origin - ) + irThis = IrGetFieldImpl(startOffset, endOffset, outerThisField.symbol, outerThisField.type, irThis, origin) val outer = innerClass.parent innerClass = outer as? IrClass ?: diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index 18bc5bc8853..09c0e7a792d 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -195,13 +195,14 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP return enumEntryClass } - private fun createFieldForEnumEntry(enumEntry: IrEnumEntry): IrField { - return context.declarationFactory.getFieldForEnumEntry(enumEntry, enumEntry.initializerExpression!!.type).also { + private fun createFieldForEnumEntry(enumEntry: IrEnumEntry): IrField = + context.declarationFactory.getFieldForEnumEntry( + enumEntry, (enumEntry.correspondingClass ?: enumEntry.parentAsClass).defaultType + ).also { it.initializer = IrExpressionBodyImpl(enumEntry.initializerExpression!!) enumEntryFields.add(it) enumEntriesByField[it] = enumEntry } - } private fun setupSynthesizedEnumClassMembers() { val irField = createSyntheticValuesFieldDeclaration() diff --git a/compiler/testData/codegen/box/classes/kt2566_2.kt b/compiler/testData/codegen/box/classes/kt2566_2.kt index e4575e2cd39..b119af85615 100644 --- a/compiler/testData/codegen/box/classes/kt2566_2.kt +++ b/compiler/testData/codegen/box/classes/kt2566_2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR open class A { open val foo: String = "OK" } diff --git a/compiler/testData/codegen/box/super/innerClassLabeledSuper.kt b/compiler/testData/codegen/box/super/innerClassLabeledSuper.kt index 7efea696d41..cbb0a875df9 100644 --- a/compiler/testData/codegen/box/super/innerClassLabeledSuper.kt +++ b/compiler/testData/codegen/box/super/innerClassLabeledSuper.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: JVM_IR interface BK { fun foo(): String fun bar(): String