diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/LateinitLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/LateinitLowering.kt index a7fcb7891db..f3ee741c15b 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/LateinitLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/LateinitLowering.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.backend.konan.lower import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.lower.* +import org.jetbrains.kotlin.backend.konan.descriptors.resolveFakeOverride import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.IrStatement @@ -98,7 +99,7 @@ internal class LateinitLowering( val propertyReference = expression.extensionReceiver!! as IrPropertyReference assert(propertyReference.extensionReceiver == null, { "'lateinit' modifier is not allowed on extension properties" }) // TODO: Take propertyReference.fieldSymbol as soon as it will show up in IR. - val propertyDescriptor = propertyReference.descriptor + val propertyDescriptor = propertyReference.descriptor.resolveFakeOverride().original val type = propertyDescriptor.type assert(!KotlinBuiltIns.isPrimitiveType(type), { "'lateinit' modifier is not allowed on primitive types" }) diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index c1490f044a5..265b1e59a57 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -1092,6 +1092,11 @@ task lateinit_globalIsInitialized(type: RunKonanTest) { source = "codegen/lateinit/globalIsInitialized.kt" } +task lateinit_innerIsInitialized(type: RunKonanTest) { + goldValue = "OK\n" + source = "codegen/lateinit/innerIsInitialized.kt" +} + task kclass0(type: RunKonanTest) { source = "codegen/kclass/kclass0.kt" } diff --git a/backend.native/tests/codegen/lateinit/innerIsInitialized.kt b/backend.native/tests/codegen/lateinit/innerIsInitialized.kt new file mode 100644 index 00000000000..6b4467bc8d5 --- /dev/null +++ b/backend.native/tests/codegen/lateinit/innerIsInitialized.kt @@ -0,0 +1,23 @@ +package codegen.lateinit.innerIsInitialized + +import kotlin.test.* + +open class Foo { + lateinit var bar: String + + fun test(): String { + return InnerSubclass().testInner() + } + + inner class InnerSubclass : Foo() { + fun testInner(): String { + // This is access to InnerSubclass.bar which is inherited from Foo.bar + if (this::bar.isInitialized) return "Fail" + return "OK" + } + } +} + +@Test fun runTest() { + println(Foo().test()) +}