[Commonizer] Fix computing outer class type arguments
This commit is contained in:
+27
-7
@@ -123,22 +123,42 @@ internal fun CirSimpleType.buildType(
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun buildSimpleType(classifier: ClassifierDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean) =
|
||||
simpleType(
|
||||
private fun buildSimpleType(classifier: ClassifierDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean): SimpleType {
|
||||
val reorderedArguments = if (arguments.isNotEmpty() && classifier is ClassDescriptor && classifier.isInner) {
|
||||
val totalArguments = arguments.size
|
||||
var remainingArguments = totalArguments
|
||||
|
||||
ArrayList<TypeProjection>(totalArguments).also { reorderedArguments ->
|
||||
var currentClassifier: ClassDescriptor = classifier
|
||||
|
||||
while (true) {
|
||||
val argumentsForCurrentClassifier = currentClassifier.declaredTypeParameters.size
|
||||
for (i in 0 until argumentsForCurrentClassifier) {
|
||||
reorderedArguments += arguments[remainingArguments - argumentsForCurrentClassifier + i]
|
||||
}
|
||||
remainingArguments -= argumentsForCurrentClassifier
|
||||
|
||||
if (remainingArguments == 0) break
|
||||
currentClassifier = currentClassifier.containingDeclaration as ClassDescriptor
|
||||
}
|
||||
}
|
||||
} else arguments
|
||||
|
||||
return simpleType(
|
||||
annotations = Annotations.EMPTY,
|
||||
constructor = classifier.typeConstructor,
|
||||
arguments = arguments,
|
||||
arguments = reorderedArguments,
|
||||
nullable = isMarkedNullable,
|
||||
kotlinTypeRefiner = null
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("NOTHING_TO_INLINE")
|
||||
private inline fun buildExpandedType(classifier: TypeAliasDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean) =
|
||||
TypeAliasExpander.NON_REPORTING.expand(
|
||||
private fun buildExpandedType(classifier: TypeAliasDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean): SimpleType {
|
||||
return TypeAliasExpander.NON_REPORTING.expand(
|
||||
TypeAliasExpansion.create(null, classifier, arguments),
|
||||
Annotations.EMPTY
|
||||
).makeNullableAsSpecified(isMarkedNullable)
|
||||
}
|
||||
|
||||
|
||||
private inline fun <reified T : ClassifierDescriptorWithTypeParameters> ClassifierDescriptorWithTypeParameters.checkClassifierType(): T {
|
||||
|
||||
@@ -61,8 +61,10 @@ sealed class CirClassOrTypeAliasType : CirSimpleType() {
|
||||
abstract val classifierId: ClassId
|
||||
abstract val arguments: List<CirTypeProjection>
|
||||
|
||||
override fun appendDescriptionTo(builder: StringBuilder) {
|
||||
builder.append(classifierId.asString())
|
||||
override fun appendDescriptionTo(builder: StringBuilder) = appendDescriptionTo(builder, shortNameOnly = false)
|
||||
|
||||
protected open fun appendDescriptionTo(builder: StringBuilder, shortNameOnly: Boolean) {
|
||||
builder.append(if (shortNameOnly) classifierId.relativeClassName.shortName().asString() else classifierId.asString())
|
||||
if (arguments.isNotEmpty()) arguments.joinTo(builder, prefix = "<", postfix = ">")
|
||||
super.appendDescriptionTo(builder)
|
||||
}
|
||||
@@ -71,12 +73,13 @@ sealed class CirClassOrTypeAliasType : CirSimpleType() {
|
||||
abstract class CirClassType : CirClassOrTypeAliasType(), CirHasVisibility {
|
||||
abstract val outerType: CirClassType?
|
||||
|
||||
override fun appendDescriptionTo(builder: StringBuilder) {
|
||||
outerType?.let {
|
||||
it.appendDescriptionTo(builder)
|
||||
override fun appendDescriptionTo(builder: StringBuilder, shortNameOnly: Boolean) {
|
||||
val outerType = outerType
|
||||
if (outerType != null) {
|
||||
outerType.appendDescriptionTo(builder)
|
||||
builder.append('.')
|
||||
}
|
||||
super.appendDescriptionTo(builder)
|
||||
super.appendDescriptionTo(builder, shortNameOnly = outerType != null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -147,10 +147,10 @@ object CirTypeFactory {
|
||||
val declaredTypeParametersCount = classDescriptor.declaredTypeParameters.size
|
||||
outerType = createClassTypeWithAllOuterTypes(
|
||||
classDescriptor = classDescriptor.containingDeclaration as ClassDescriptor,
|
||||
arguments = arguments.subList(0, arguments.size - declaredTypeParametersCount),
|
||||
arguments = arguments.subList(declaredTypeParametersCount, arguments.size),
|
||||
isMarkedNullable = false // don't pass nullable flag to outer types
|
||||
)
|
||||
remainingArguments = arguments.subList(arguments.size - declaredTypeParametersCount, arguments.size)
|
||||
remainingArguments = arguments.subList(0, declaredTypeParametersCount)
|
||||
} else {
|
||||
outerType = null
|
||||
remainingArguments = arguments
|
||||
|
||||
Reference in New Issue
Block a user