[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 fun buildSimpleType(classifier: ClassifierDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean): SimpleType {
|
||||||
private inline fun buildSimpleType(classifier: ClassifierDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean) =
|
val reorderedArguments = if (arguments.isNotEmpty() && classifier is ClassDescriptor && classifier.isInner) {
|
||||||
simpleType(
|
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,
|
annotations = Annotations.EMPTY,
|
||||||
constructor = classifier.typeConstructor,
|
constructor = classifier.typeConstructor,
|
||||||
arguments = arguments,
|
arguments = reorderedArguments,
|
||||||
nullable = isMarkedNullable,
|
nullable = isMarkedNullable,
|
||||||
kotlinTypeRefiner = null
|
kotlinTypeRefiner = null
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Suppress("NOTHING_TO_INLINE")
|
private fun buildExpandedType(classifier: TypeAliasDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean): SimpleType {
|
||||||
private inline fun buildExpandedType(classifier: TypeAliasDescriptor, arguments: List<TypeProjection>, isMarkedNullable: Boolean) =
|
return TypeAliasExpander.NON_REPORTING.expand(
|
||||||
TypeAliasExpander.NON_REPORTING.expand(
|
|
||||||
TypeAliasExpansion.create(null, classifier, arguments),
|
TypeAliasExpansion.create(null, classifier, arguments),
|
||||||
Annotations.EMPTY
|
Annotations.EMPTY
|
||||||
).makeNullableAsSpecified(isMarkedNullable)
|
).makeNullableAsSpecified(isMarkedNullable)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private inline fun <reified T : ClassifierDescriptorWithTypeParameters> ClassifierDescriptorWithTypeParameters.checkClassifierType(): T {
|
private inline fun <reified T : ClassifierDescriptorWithTypeParameters> ClassifierDescriptorWithTypeParameters.checkClassifierType(): T {
|
||||||
|
|||||||
@@ -61,8 +61,10 @@ sealed class CirClassOrTypeAliasType : CirSimpleType() {
|
|||||||
abstract val classifierId: ClassId
|
abstract val classifierId: ClassId
|
||||||
abstract val arguments: List<CirTypeProjection>
|
abstract val arguments: List<CirTypeProjection>
|
||||||
|
|
||||||
override fun appendDescriptionTo(builder: StringBuilder) {
|
override fun appendDescriptionTo(builder: StringBuilder) = appendDescriptionTo(builder, shortNameOnly = false)
|
||||||
builder.append(classifierId.asString())
|
|
||||||
|
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 = ">")
|
if (arguments.isNotEmpty()) arguments.joinTo(builder, prefix = "<", postfix = ">")
|
||||||
super.appendDescriptionTo(builder)
|
super.appendDescriptionTo(builder)
|
||||||
}
|
}
|
||||||
@@ -71,12 +73,13 @@ sealed class CirClassOrTypeAliasType : CirSimpleType() {
|
|||||||
abstract class CirClassType : CirClassOrTypeAliasType(), CirHasVisibility {
|
abstract class CirClassType : CirClassOrTypeAliasType(), CirHasVisibility {
|
||||||
abstract val outerType: CirClassType?
|
abstract val outerType: CirClassType?
|
||||||
|
|
||||||
override fun appendDescriptionTo(builder: StringBuilder) {
|
override fun appendDescriptionTo(builder: StringBuilder, shortNameOnly: Boolean) {
|
||||||
outerType?.let {
|
val outerType = outerType
|
||||||
it.appendDescriptionTo(builder)
|
if (outerType != null) {
|
||||||
|
outerType.appendDescriptionTo(builder)
|
||||||
builder.append('.')
|
builder.append('.')
|
||||||
}
|
}
|
||||||
super.appendDescriptionTo(builder)
|
super.appendDescriptionTo(builder, shortNameOnly = outerType != null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -147,10 +147,10 @@ object CirTypeFactory {
|
|||||||
val declaredTypeParametersCount = classDescriptor.declaredTypeParameters.size
|
val declaredTypeParametersCount = classDescriptor.declaredTypeParameters.size
|
||||||
outerType = createClassTypeWithAllOuterTypes(
|
outerType = createClassTypeWithAllOuterTypes(
|
||||||
classDescriptor = classDescriptor.containingDeclaration as ClassDescriptor,
|
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
|
isMarkedNullable = false // don't pass nullable flag to outer types
|
||||||
)
|
)
|
||||||
remainingArguments = arguments.subList(arguments.size - declaredTypeParametersCount, arguments.size)
|
remainingArguments = arguments.subList(0, declaredTypeParametersCount)
|
||||||
} else {
|
} else {
|
||||||
outerType = null
|
outerType = null
|
||||||
remainingArguments = arguments
|
remainingArguments = arguments
|
||||||
|
|||||||
Reference in New Issue
Block a user