File tree Expand file tree Collapse file tree 3 files changed +13
-4
lines changed
fir/entrypoint/src/org/jetbrains/kotlin/fir/backend
ir/ir.tree/src/org/jetbrains/kotlin/ir/types
testData/codegen/box/classDelegation Expand file tree Collapse file tree 3 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -386,7 +386,7 @@ class Fir2IrDelegatedMembersGenerationStrategy(
386386
387387 val irCastOrCall = if (
388388 delegateTargetFunction.returnType.let { it.hasAnnotation(FlexibleNullability ) || it.hasAnnotation(EnhancedNullability ) } &&
389- ! delegatedFunction.returnType.isMarkedNullable ()
389+ ! delegatedFunction.returnType.canBeNull ()
390390 ) {
391391 Fir2IrImplicitCastInserter .implicitNotNullCast(irCall)
392392 } else {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
1212import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
1313import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
1414import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
15+ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
1516import org.jetbrains.kotlin.ir.types.impl.IrCapturedType
1617import org.jetbrains.kotlin.ir.util.IdSignature
1718import org.jetbrains.kotlin.ir.util.hasEqualFqName
@@ -158,8 +159,17 @@ fun <T : Enum<T>> IrType.getPrimitiveOrUnsignedType(byIdSignature: Map<IdSignatu
158159 return byShortName[klass.name]
159160}
160161
161- fun IrType.isMarkedNullable () = (this as ? IrSimpleType )?.nullability == SimpleTypeNullability .MARKED_NULLABLE
162- fun IrSimpleType.isMarkedNullable () = nullability == SimpleTypeNullability .MARKED_NULLABLE
162+ fun IrType.isMarkedNullable (): Boolean = (this as ? IrSimpleType )?.nullability == SimpleTypeNullability .MARKED_NULLABLE
163+ fun IrSimpleType.isMarkedNullable (): Boolean = nullability == SimpleTypeNullability .MARKED_NULLABLE
164+
165+ fun IrType.canBeNull (): Boolean = when (this ) {
166+ is IrSimpleType -> isMarkedNullable() || when (this ) {
167+ is IrCapturedType -> constructor .superTypes.any { it.canBeNull() }
168+ else -> (classifier as ? IrTypeParameterSymbol )?.owner?.superTypes?.all { it.canBeNull() } ? : false
169+ }
170+ is IrDynamicType -> true
171+ is IrErrorType -> isMarkedNullable
172+ }
163173
164174fun IrType.isUnit () = isNotNullClassType(IdSignatureValues .unit)
165175
Original file line number Diff line number Diff line change 11// TARGET_BACKEND: JVM_IR
2- // IGNORE_BACKEND_K2: JVM_IR
32// FULL_JDK
43// ISSUE: KT-79816
54
You can’t perform that action at this time.
0 commit comments