[IR] Use extractTypeParameter instead of collectTypeParameters
^KT-45866 fixed
This commit is contained in:
committed by
TeamCityServer
parent
5955faecec
commit
b976cd812a
+9
-6
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.ir.types.extractTypeParameters
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
@@ -106,8 +107,8 @@ class ExpectDeclarationRemover(val symbolTable: ReferenceSymbolTable, private va
|
||||
|
||||
val expectToActual = expectFunction to function
|
||||
if (expectToActual !in typeParameterSubstitutionMap) {
|
||||
val functionTypeParameters = collectTypeParameters(function)
|
||||
val expectFunctionTypeParameters = collectTypeParameters(expectFunction)
|
||||
val functionTypeParameters = extractTypeParameters(function)
|
||||
val expectFunctionTypeParameters = extractTypeParameters(expectFunction)
|
||||
|
||||
expectFunctionTypeParameters.zip(functionTypeParameters).let { typeParametersMapping ->
|
||||
typeParameterSubstitutionMap[expectToActual] = typeParametersMapping.toMap()
|
||||
@@ -117,11 +118,13 @@ class ExpectDeclarationRemover(val symbolTable: ReferenceSymbolTable, private va
|
||||
defaultValue.let { originalDefault ->
|
||||
declaration.defaultValue = declaration.factory.createExpressionBody(originalDefault.startOffset, originalDefault.endOffset) {
|
||||
expression = originalDefault.expression
|
||||
.deepCopyWithSymbols(function)
|
||||
.remapExpectValueSymbols()
|
||||
.apply {
|
||||
remapTypes(IrTypeParameterRemapper(typeParameterSubstitutionMap.getValue(expectToActual)))
|
||||
.deepCopyWithSymbols(function) { symbolRemapper, _ ->
|
||||
DeepCopyIrTreeWithSymbols(
|
||||
symbolRemapper,
|
||||
IrTypeParameterRemapper(typeParameterSubstitutionMap.getValue(expectToActual))
|
||||
)
|
||||
}
|
||||
.remapExpectValueSymbols()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.transformStatement
|
||||
import org.jetbrains.kotlin.ir.types.extractTypeParameters
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
@@ -350,6 +351,6 @@ class InlineClassLowering(val context: CommonBackendContext) {
|
||||
function.parent,
|
||||
function.toInlineClassImplementationName(),
|
||||
function,
|
||||
typeParametersFromContext = collectTypeParameters(function.parentAsClass)
|
||||
typeParametersFromContext = extractTypeParameters(function.parentAsClass)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -602,20 +602,4 @@ internal fun <T> IrConst<T>.shallowCopy() = IrConstImpl(
|
||||
type,
|
||||
kind,
|
||||
value
|
||||
)
|
||||
|
||||
fun collectTypeParameters(declaration: IrTypeParametersContainer): List<IrTypeParameter> {
|
||||
val result = mutableListOf<IrTypeParameter>()
|
||||
|
||||
fun collectImpl(declaration: IrDeclaration) {
|
||||
if (declaration is IrTypeParametersContainer) {
|
||||
result.addAll(declaration.typeParameters)
|
||||
declaration.parentClassOrNull?.let { collectImpl(it) }
|
||||
}
|
||||
if (declaration is IrClass && declaration.isInner) collectImpl(declaration.parent as IrDeclaration)
|
||||
}
|
||||
|
||||
collectImpl(declaration)
|
||||
|
||||
return result
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user