JVM_IR. Support annotation classes with JvmField fields

This commit is contained in:
Georgy Bronnikov
2018-10-15 17:33:30 +03:00
parent 605afbae90
commit bbac1d802f
7 changed files with 5 additions and 8 deletions
@@ -289,8 +289,7 @@ private val MemberDescriptor.effectiveModality: Modality
}
}
if (DescriptorUtils.isSealedClass(this) ||
DescriptorUtils.isAnnotationClass(this) ||
DescriptorUtils.isAnnotationClass(this.containingDeclaration)
DescriptorUtils.isAnnotationClass(this)
) {
return Modality.ABSTRACT
}
@@ -76,7 +76,7 @@ open class FunctionCodegen(private val irFunction: IrFunction, private val class
val deprecation = if (irFunction.hasAnnotation(FQ_NAMES.deprecated)) Opcodes.ACC_DEPRECATED else 0
val bridgeFlag = 0 //TODO
val modalityFlag = when ((irFunction as? IrSimpleFunction)?.modality) {
Modality.FINAL -> if (!classCodegen.irClass.isAnnotationClass) Opcodes.ACC_FINAL else Opcodes.ACC_ABSTRACT
Modality.FINAL -> if (!classCodegen.irClass.isAnnotationClass || irFunction.isStatic) Opcodes.ACC_FINAL else Opcodes.ACC_ABSTRACT
Modality.ABSTRACT -> Opcodes.ACC_ABSTRACT
else -> if (classCodegen.irClass.isJvmInterface && irFunction.body == null) Opcodes.ACC_ABSTRACT else 0 //TODO transform interface modality on lowering to DefaultImpls
}
@@ -40,7 +40,7 @@ class ConstAndJvmFieldPropertiesLowering(val context: CommonBackendContext) : Ir
val irProperty = irSimpleFunction.correspondingProperty ?: return super.visitCall(expression)
if (irProperty.isConst) {
(irProperty.backingField?.initializer?.expression as? IrConst<*>)?.let { return it }
(irProperty.backingField!!.initializer!!.expression as IrConst<*>).let { return it }
}
if (irProperty.backingField?.hasAnnotation(JVM_FIELD_ANNOTATION_FQ_NAME) == true) {
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.ir.util.isAnnotationClass
import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.isObject
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
@@ -60,7 +61,7 @@ class MoveCompanionObjectFieldsLowering(val context: CommonBackendContext) : Cla
val companion = irClass.declarations.find {
it is IrClass && it.isCompanion
} as IrClass? ?: return
if (irClass.isInterface && !companion.allFieldsAreJvmField()) return
if ((irClass.isInterface || irClass.isAnnotationClass) && !companion.allFieldsAreJvmField()) return
companion.declarations.forEach {
when (it) {
is IrProperty -> {
@@ -1,5 +1,4 @@
// !LANGUAGE: +NestedClassesInAnnotations
// IGNORE_BACKEND: JVM_IR
// IGNORE_BACKEND: NATIVE
annotation class Foo(val kind: Kind) {
@@ -1,5 +1,4 @@
// !LANGUAGE: +JvmFieldInInterface +NestedClassesInAnnotations
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME
@@ -1,5 +1,4 @@
// !LANGUAGE: +JvmFieldInInterface +NestedClassesInAnnotations
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// WITH_RUNTIME