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(
386
386
387
387
val irCastOrCall = if (
388
388
delegateTargetFunction.returnType.let { it.hasAnnotation(FlexibleNullability ) || it.hasAnnotation(EnhancedNullability ) } &&
389
- ! delegatedFunction.returnType.isMarkedNullable ()
389
+ ! delegatedFunction.returnType.canBeNull ()
390
390
) {
391
391
Fir2IrImplicitCastInserter .implicitNotNullCast(irCall)
392
392
} else {
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
12
12
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
13
13
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
14
14
import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol
15
+ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
15
16
import org.jetbrains.kotlin.ir.types.impl.IrCapturedType
16
17
import org.jetbrains.kotlin.ir.util.IdSignature
17
18
import org.jetbrains.kotlin.ir.util.hasEqualFqName
@@ -158,8 +159,17 @@ fun <T : Enum<T>> IrType.getPrimitiveOrUnsignedType(byIdSignature: Map<IdSignatu
158
159
return byShortName[klass.name]
159
160
}
160
161
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
+ }
163
173
164
174
fun IrType.isUnit () = isNotNullClassType(IdSignatureValues .unit)
165
175
Original file line number Diff line number Diff line change 1
1
// TARGET_BACKEND: JVM_IR
2
- // IGNORE_BACKEND_K2: JVM_IR
3
2
// FULL_JDK
4
3
// ISSUE: KT-79816
5
4
You can’t perform that action at this time.
0 commit comments