Skip to content

Commit b35db97

Browse files
author
Alfonso
committed
Check if target.typeParameters gracefully
1 parent 68fc9cd commit b35db97

File tree

1 file changed

+22
-29
lines changed
  • compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util

1 file changed

+22
-29
lines changed

compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/IrUtils.kt

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,40 +1008,33 @@ fun IrType.remapTypeParameters(
10081008
srcToDstParameterMap: Map<IrTypeParameter, IrTypeParameter>? = null
10091009
): IrType =
10101010
when (this) {
1011-
is IrSimpleType -> {
1011+
is IrSimpleType if (classifier.owner is IrTypeParameter || classifier.owner is IrClass) -> {
10121012
val classifier = classifier.owner
1013-
when {
1014-
classifier is IrTypeParameter -> {
1015-
val newClassifier =
1016-
srcToDstParameterMap?.get(classifier) ?: if (classifier.parent == source)
1017-
target.typeParameters[classifier.index]
1018-
else
1019-
classifier
1020-
IrSimpleTypeImpl(newClassifier.symbol, nullability, arguments, annotations)
1021-
}
1022-
1023-
classifier is IrClass ->
1024-
IrSimpleTypeImpl(
1025-
classifier.symbol,
1026-
nullability,
1027-
arguments.memoryOptimizedMap {
1028-
when (it) {
1029-
is IrTypeProjection -> makeTypeProjection(
1030-
it.type.remapTypeParameters(source, target, srcToDstParameterMap),
1031-
it.variance
1032-
)
1033-
is IrStarProjection -> it
1034-
}
1035-
},
1036-
annotations
1037-
)
1038-
1039-
else -> this
1040-
}
1013+
val newSymbol: IrClassifierSymbol = when (classifier) {
1014+
is IrTypeParameter if srcToDstParameterMap?.get(classifier) != null -> srcToDstParameterMap[classifier]!!.symbol
1015+
is IrTypeParameter if classifier.parent == source && target.typeParameters.size > classifier.index -> target.typeParameters[classifier.index].symbol
1016+
else -> classifier.symbol
1017+
} as IrClassifierSymbol
1018+
1019+
IrSimpleTypeImpl(
1020+
newSymbol,
1021+
nullability,
1022+
if (classifier is IrClass) arguments.memoryOptimizedMap {
1023+
when (it) {
1024+
is IrTypeProjection -> makeTypeProjection(
1025+
it.type.remapTypeParameters(source, target, srcToDstParameterMap),
1026+
it.variance
1027+
)
1028+
is IrStarProjection -> it
1029+
}
1030+
} else arguments,
1031+
annotations
1032+
)
10411033
}
10421034
else -> this
10431035
}
10441036

1037+
10451038
fun IrDeclarationContainer.addChild(declaration: IrDeclaration) {
10461039
this.declarations += declaration
10471040
declaration.setDeclarationsParent(this)

0 commit comments

Comments
 (0)