[Commonizer] Fix: approximate signatures with type parameter upper bounds
This commit is contained in:
+2
-2
@@ -47,8 +47,8 @@ class CirSimpleType(private val wrapped: SimpleType) : CirType() {
|
|||||||
val isDefinitelyNotNullType get() = abbreviation.isDefinitelyNotNullType
|
val isDefinitelyNotNullType get() = abbreviation.isDefinitelyNotNullType
|
||||||
val expandedTypeConstructorId by lazy(PUBLICATION) { CirTypeConstructorId(expanded) }
|
val expandedTypeConstructorId by lazy(PUBLICATION) { CirTypeConstructorId(expanded) }
|
||||||
|
|
||||||
inline val isClassOrTypeAlias: Boolean get() = (kind == CLASS || kind == TYPE_ALIAS)
|
inline val isClassOrTypeAlias get() = (kind == CLASS || kind == TYPE_ALIAS)
|
||||||
val fqNameWithTypeParameters: String get() = wrapped.fqNameWithTypeParameters
|
val fqNameWithTypeParameters by lazy(PUBLICATION) { wrapped.fqNameWithTypeParameters }
|
||||||
|
|
||||||
override fun equals(other: Any?) = wrapped == (other as? CirSimpleType)?.wrapped
|
override fun equals(other: Any?) = wrapped == (other as? CirSimpleType)?.wrapped
|
||||||
override fun hashCode() = wrapped.hashCode()
|
override fun hashCode() = wrapped.hashCode()
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
import org.jetbrains.kotlin.types.TypeUtils.getTypeParameterDescriptorOrNull
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
import org.jetbrains.kotlin.types.isNullable
|
||||||
|
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
|
|
||||||
internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
|
internal fun <T> Sequence<T>.toList(expectedCapacity: Int): List<T> {
|
||||||
@@ -29,29 +32,49 @@ internal inline val KotlinType.fqName: FqName
|
|||||||
get() = declarationDescriptor.fqNameSafe
|
get() = declarationDescriptor.fqNameSafe
|
||||||
|
|
||||||
internal val KotlinType.fqNameWithTypeParameters: String
|
internal val KotlinType.fqNameWithTypeParameters: String
|
||||||
get() = buildString { buildFqNameWithTypeParameters(this@fqNameWithTypeParameters) }
|
get() = buildString { buildFqNameWithTypeParameters(this@fqNameWithTypeParameters, HashSet()) }
|
||||||
|
|
||||||
private fun StringBuilder.buildFqNameWithTypeParameters(type: KotlinType) {
|
private fun StringBuilder.buildFqNameWithTypeParameters(type: KotlinType, exploredTypeParameters: MutableSet<KotlinType>) {
|
||||||
append(type.fqName)
|
append(type.fqName)
|
||||||
|
|
||||||
val arguments = type.arguments
|
val typeParameterDescriptor = getTypeParameterDescriptorOrNull(type)
|
||||||
if (arguments.isNotEmpty()) {
|
if (typeParameterDescriptor != null) {
|
||||||
append("<")
|
// N.B this is type parameter type
|
||||||
arguments.forEachIndexed { index, argument ->
|
|
||||||
if (index > 0)
|
|
||||||
append(",")
|
|
||||||
|
|
||||||
if (argument.isStarProjection)
|
if (exploredTypeParameters.add(type.makeNotNullable())) { // print upper bounds once the first time when type parameter type is met
|
||||||
append("*")
|
append(":[")
|
||||||
else {
|
typeParameterDescriptor.upperBounds.forEachIndexed { index, upperBound ->
|
||||||
val variance = argument.projectionKind
|
if (index > 0)
|
||||||
if (variance != Variance.INVARIANT)
|
append(",")
|
||||||
append(variance).append(" ")
|
buildFqNameWithTypeParameters(upperBound, exploredTypeParameters)
|
||||||
buildFqNameWithTypeParameters(argument.type)
|
|
||||||
}
|
}
|
||||||
|
append("]")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// N.B. this is classifier type
|
||||||
|
|
||||||
|
val arguments = type.arguments
|
||||||
|
if (arguments.isNotEmpty()) {
|
||||||
|
append("<")
|
||||||
|
arguments.forEachIndexed { index, argument ->
|
||||||
|
if (index > 0)
|
||||||
|
append(",")
|
||||||
|
|
||||||
|
if (argument.isStarProjection)
|
||||||
|
append("*")
|
||||||
|
else {
|
||||||
|
val variance = argument.projectionKind
|
||||||
|
if (variance != Variance.INVARIANT)
|
||||||
|
append(variance).append(" ")
|
||||||
|
buildFqNameWithTypeParameters(argument.type, exploredTypeParameters)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
append(">")
|
||||||
}
|
}
|
||||||
append(">")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type.isMarkedNullable)
|
||||||
|
append("?")
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Any?.isNull(): Boolean = this == null
|
internal fun Any?.isNull(): Boolean = this == null
|
||||||
|
|||||||
Reference in New Issue
Block a user