Report error on unsupported fields of Companion in ObjC subclass [KT-36041] (#4054)
Co-authored-by: Vladimir Ivanov <vladimir.d.ivanov@jetbrains.com>
This commit is contained in:
+2
-2
@@ -27,7 +27,7 @@ internal class KotlinObjCClassInfoGenerator(override val context: Context) : Con
|
||||
|
||||
val instanceMethods = generateInstanceMethodDescs(irClass)
|
||||
|
||||
val companionObject = irClass.declarations.filterIsInstance<IrClass>().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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user