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:
Vladimir Ivanov
2020-04-06 10:39:33 +03:00
committed by GitHub
parent 4ee712c5d7
commit e6a227bb07
2 changed files with 21 additions and 2 deletions
@@ -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
}
}
}
@@ -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