Refactoring: Improve createExpectActualTypeParameterSubstitutor API
Review: https://jetbrains.team/p/kt/reviews/12279/files Motivation: make sure that cases like KT-62027 won't happen again Review: https://jetbrains.team/p/kt/reviews/12279/files Now it's responsibility of the `createExpectActualTypeParameterSubstitutor` calller to think about the case when parameters size isn't equal. You must not be able to create a substitutor if type parameters sizes are not equal Improvement in `createExpectActualTypeParameterSubstitutor` API also improves `AbstractExpectActualCompatibilityChecker.getCallablesCompatibility` API. Because suppose that you accidentally created a redundant wrapping substitutor => you need to handle the case of not equal type parameters size on the call site => you start thinking why you should do that on the call site? It must be a responsibility of `getCallablesCompatibility` => you realize that you created a redundant wrapping substitutor
This commit is contained in:
+3
-5
@@ -208,8 +208,6 @@ class IrBodyDeserializer(
|
||||
return IrSimpleTypeBuilder().apply { classifier = klass.symbol }.buildSimpleType()
|
||||
}
|
||||
|
||||
val typeArguments = ArrayList<IrTypeArgument>(typeParameters.size)
|
||||
val typeParameterSymbols = ArrayList<IrTypeParameterSymbol>(typeParameters.size)
|
||||
val rawType = with(IrSimpleTypeBuilder()) {
|
||||
arguments = typeParameters.memoryOptimizedMap {
|
||||
classifier = it.symbol
|
||||
@@ -219,15 +217,15 @@ class IrBodyDeserializer(
|
||||
buildSimpleType()
|
||||
}
|
||||
|
||||
val typeParametersToArguments = HashMap<IrTypeParameterSymbol, IrTypeArgument>(typeParameters.size)
|
||||
for (i in typeParameters.indices) {
|
||||
val typeParameter = typeParameters[i]
|
||||
val callTypeArgument = constructorCall.getTypeArgument(i) ?: error("No type argument for id $i")
|
||||
val typeArgument = makeTypeProjection(callTypeArgument, typeParameter.variance)
|
||||
typeArguments.add(typeArgument)
|
||||
typeParameterSymbols.add(typeParameter.symbol)
|
||||
typeParametersToArguments[typeParameter.symbol] = typeArgument
|
||||
}
|
||||
|
||||
val substitutor = IrTypeSubstitutor(typeParameterSymbols, typeArguments)
|
||||
val substitutor = IrTypeSubstitutor(typeParametersToArguments)
|
||||
return substitutor.substitute(rawType) as IrSimpleType
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user