diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/KotlinObjCClassInfoGenerator.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/KotlinObjCClassInfoGenerator.kt index 7c0717f7b95..ba7270dfdd0 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/KotlinObjCClassInfoGenerator.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/llvm/KotlinObjCClassInfoGenerator.kt @@ -27,7 +27,7 @@ internal class KotlinObjCClassInfoGenerator(override val context: Context) : Con val instanceMethods = generateInstanceMethodDescs(irClass) - val companionObject = irClass.declarations.filterIsInstance().atMostOne { it.isCompanion } + val companionObject = irClass.companionObject() val classMethods = companionObject?.generateMethodDescs().orEmpty() val superclassName = irClass.getSuperClassNotAny()!!.let { @@ -147,4 +147,4 @@ internal fun CodeGenerator.kotlinObjCClassInfo(irClass: IrClass): LLVMValueRef { } else { context.llvmDeclarations.forClass(irClass).objCDeclarations!!.classInfoGlobal.llvmGlobal } -} \ No newline at end of file +} diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt index 96367d6aaeb..dc237d76ed7 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/InteropLowering.kt @@ -466,6 +466,15 @@ private class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfor } } + private fun IrClass.hasFields() = + this.declarations.any { + when (it) { + is IrField -> it.isReal + is IrProperty -> it.isReal && it.backingField != null + else -> false + } + } + private fun checkKotlinObjCClass(irClass: IrClass) { val kind = irClass.descriptor.kind if (kind != ClassKind.CLASS && kind != ClassKind.OBJECT) { @@ -482,6 +491,16 @@ private class InteropLoweringPart1(val context: Context) : BaseInteropIrTransfor ) } + irClass.companionObject()?.let { + if (it.hasFields() || + it.getSuperClassNotAny()?.hasFields() ?: false) { + context.reportCompilationError( + "Fields are not supported for Companion of subclass of ObjC type", + currentFile, irClass + ) + } + } + var hasObjCClassSupertype = false irClass.descriptor.defaultType.constructor.supertypes.forEach { val descriptor = it.constructor.declarationDescriptor as ClassDescriptor