interface IrType { } interface TypeRemapper { abstract fun enterScope(irTypeParametersContainer: IrTypeParametersContainer) abstract fun remapType(type: IrType): IrType abstract fun leaveScope() } interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent { abstract var typeParameters: List abstract get abstract set } interface IrDeclaration { } interface IrTypeParameter : IrDeclaration { abstract val superTypes: MutableList abstract get } interface IrDeclarationParent { } class DeepCopyIrTreeWithSymbols { constructor(typeRemapper: TypeRemapper) /* primary */ { super/*Any*/() /* () */ } private val typeRemapper: TypeRemapper field = typeRemapper private get private fun copyTypeParameter(declaration: IrTypeParameter): IrTypeParameter { return declaration } fun IrTypeParametersContainer.copyTypeParametersFrom(other: IrTypeParametersContainer) { .( = other.().map(transform = local fun (it: IrTypeParameter): IrTypeParameter { return .copyTypeParameter(declaration = it) } )) .().withinScope(irTypeParametersContainer = , fn = local fun () { { // BLOCK val : Iterator> = .().zip(other = other.()).iterator() while (.hasNext()) { // BLOCK val : Pair = .next() val thisTypeParameter: IrTypeParameter = .component1() val otherTypeParameter: IrTypeParameter = .component2() otherTypeParameter.().mapTo>(destination = thisTypeParameter.(), transform = local fun (it: IrType): IrType { return .().remapType(type = it) } ) } } } ) } } inline fun TypeRemapper.withinScope(irTypeParametersContainer: IrTypeParametersContainer, fn: Function0): T { .enterScope(irTypeParametersContainer = irTypeParametersContainer) val result: T = fn.invoke() .leaveScope() return result }