JVM: do not put public field access into a single expression block

It affects the `is IrGetField` check in
TypeOperatorLowering.computeNotNullAssertionText, which leads to missing
NPE messages when accessing backing fields of public properties.

 #KT-64615
This commit is contained in:
Alexander Udalov
2024-01-09 00:10:46 +01:00
committed by Space Team
parent 96b2f13397
commit f01e633f8b
12 changed files with 92 additions and 1 deletions
@@ -136,9 +136,12 @@ class JvmOptimizationLowering(val context: JvmBackendContext) : FileLoweringPass
} else {
+irGetField(receiver.takeUnless { backingField.isStatic }, backingField)
}
}
}.unwrapSingleExpressionBlock()
}
private fun IrExpression.unwrapSingleExpressionBlock(): IrExpression =
(this as? IrBlock)?.statements?.singleOrNull() as? IrExpression ?: this
override fun visitWhen(expression: IrWhen, data: IrDeclaration?): IrExpression {
val isCompilerGenerated = expression.origin == null
expression.transformChildren(this, data)