JVM IR: Don't move inaccessible const fields out of interface companions
This commit is contained in:
committed by
max-kammerer
parent
3742425547
commit
0c3c0989b4
+8
-4
@@ -27,7 +27,9 @@ import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||
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.*
|
||||
import org.jetbrains.kotlin.ir.util.hasAnnotation
|
||||
import org.jetbrains.kotlin.ir.util.isObject
|
||||
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi.JVM_FIELD_ANNOTATION_FQ_NAME
|
||||
@@ -96,11 +98,13 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: CommonBackend
|
||||
val companion = irClass.declarations.find {
|
||||
it is IrClass && it.isCompanion
|
||||
} as IrClass? ?: return
|
||||
companion.declarations.filter { it is IrProperty && it.isConst }.mapNotNullTo(irClass.declarations) {
|
||||
copyPropertyFieldToStaticParent(it as IrProperty, companion, irClass)
|
||||
}
|
||||
companion.declarations.filter { it is IrProperty && it.isConst && it.hasPublicVisibility }
|
||||
.mapNotNullTo(irClass.declarations) { copyPropertyFieldToStaticParent(it as IrProperty, companion, irClass) }
|
||||
}
|
||||
|
||||
private val IrProperty.hasPublicVisibility: Boolean
|
||||
get() = !Visibilities.isPrivate(visibility) && visibility != Visibilities.PROTECTED
|
||||
|
||||
private fun IrClass.allFieldsAreJvmField() =
|
||||
declarations.filterIsInstance<IrProperty>()
|
||||
.mapNotNull { it.backingField }.all { it.hasAnnotation(JVM_FIELD_ANNOTATION_FQ_NAME) }
|
||||
|
||||
Reference in New Issue
Block a user