JVM_IR merge annotations when substituting types

Otherwise special annotations such as @EnhancedNullability are lost,
which affects JVM signatures.

KT-42330
This commit is contained in:
Dmitry Petrov
2020-09-30 13:14:12 +03:00
parent 4b152a635e
commit af86c52101
8 changed files with 127 additions and 10 deletions
@@ -82,8 +82,16 @@ fun IrType.substitute(params: List<IrTypeParameter>, arguments: List<IrType>): I
fun IrType.substitute(substitutionMap: Map<IrTypeParameterSymbol, IrType>): IrType {
if (this !is IrSimpleType) return this
substitutionMap[classifier]?.let {
return it.withHasQuestionMark(hasQuestionMark || it is IrSimpleType && it.hasQuestionMark)
val newAnnotations = annotations.map { it.deepCopyWithSymbols() }
substitutionMap[classifier]?.let { substitutedType ->
// Add nullability and annotations from original type
return substitutedType
.withHasQuestionMark(
hasQuestionMark ||
substitutedType is IrSimpleType && substitutedType.hasQuestionMark
)
.addAnnotations(newAnnotations)
}
val newArguments = arguments.map {
@@ -94,7 +102,6 @@ fun IrType.substitute(substitutionMap: Map<IrTypeParameterSymbol, IrType>): IrTy
}
}
val newAnnotations = annotations.map { it.deepCopyWithSymbols() }
return IrSimpleTypeImpl(
classifier,
hasQuestionMark,