From a2dda9e25b8a24471ee835d6e34bce0d28e03012 Mon Sep 17 00:00:00 2001 From: "marat.akhin" Date: Tue, 11 Jul 2023 10:53:20 +0200 Subject: [PATCH] [IR] Transfer type annotations when substituting via IR substitutor Other type substitutors (classic, cone-based) respect the type annotations and copy them to the resulting type for all cases, including type parameters. Without this change we cannot correctly match expect/actuals when we replace actual type parameters with expect ones in case the actual type parameter has type enhancement annotations (e.g., `@FlexibleNullability`). We transfer all annotations (and not conservatively copy only type enhancement annotations), as 1) other substitutors do that 2) other IR type substitution utilities (e.g., `IrType.substitute`) do that. As we will attempt reimplementing all IR type substitution utilities via IrTypeSubstitutor, it also makes sense to completely align the behavior. --- .../src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt index aec1aa75d48..90b6496fef6 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeSubstitutor.kt @@ -38,6 +38,7 @@ abstract class BaseIrTypeSubstitutor(private val irBuiltIns: IrBuiltIns) : Abstr when (val typeArgument = getSubstitutionArgument(it)) { is IrStarProjection -> irBuiltIns.anyNType // TODO upper bound for T is IrTypeProjection -> typeArgument.type.mergeNullability(irType) + .addAnnotations(irType.annotations) } } if (substitutedTypeParameter != null) {