From ba4b84a7d0ed6c40a48649c8f9993bd55fbb5a36 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 21 Aug 2023 13:12:33 +0300 Subject: [PATCH] [FIR2IR] Safely access IrSymbol.owner in Fir2IrImplicitCastInserter ^KT-60924 --- .../kotlin/fir/backend/Fir2IrImplicitCastInserter.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt index 022b4527438..83b93eea5b3 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt @@ -353,12 +353,18 @@ class Fir2IrImplicitCastInserter( ) } - @OptIn(IrSymbolInternals::class) internal fun implicitNotNullCast(original: IrExpression): IrTypeOperatorCall { // Cast type massage 1. Remove @EnhancedNullability // Cast type massage 2. Convert it to a non-null variant (in case of @FlexibleNullability) - val castType = original.type.removeAnnotations { - val classId = it.symbol.owner.parentAsClass.classId + val castType = original.type.removeAnnotations { annotationCall -> + val constructorSymbol = annotationCall.symbol.takeIf { it.isBound } ?: return@removeAnnotations false + /* + * @EnhancedNullability and @FlexibleNullability are symbols from builtins and should be already + * bound at the time of body conversion, so it's safe to take the owner for them + * If symbol is unbound then this annotation can not be neither @EnhancedNullability or @FlexibleNullability + */ + @OptIn(IrSymbolInternals::class) + val classId = constructorSymbol.owner.parentAsClass.classId classId == StandardClassIds.Annotations.EnhancedNullability || classId == StandardClassIds.Annotations.FlexibleNullability }.makeNotNull()