[Commonizer] Fix CirConversions and substitute arguments
CirConversions did not cover some potential convertible types. ClassOrTypeAliasTypeCommonizer did not apply type substitution for parameterized types coming from a dependency ^KT-48288
This commit is contained in:
committed by
Space
parent
e2343094ec
commit
4349f98954
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
|||||||
|
|
||||||
internal fun CirProvidedClassifiers.toCirClassOrTypeAliasTypeOrNull(type: CirProvided.ClassOrTypeAliasType): CirClassOrTypeAliasType? {
|
internal fun CirProvidedClassifiers.toCirClassOrTypeAliasTypeOrNull(type: CirProvided.ClassOrTypeAliasType): CirClassOrTypeAliasType? {
|
||||||
return when (type) {
|
return when (type) {
|
||||||
is CirProvided.ClassType -> type.toCirClassTypeOrNull()
|
is CirProvided.ClassType -> toCirClassTypeOrNull(type)
|
||||||
is CirProvided.TypeAliasType -> toCirTypeAliasTypeOrNull(type)
|
is CirProvided.TypeAliasType -> toCirTypeAliasTypeOrNull(type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,27 +21,36 @@ internal fun CirProvidedClassifiers.toCirTypeAliasTypeOrNull(type: CirProvided.T
|
|||||||
return CirTypeAliasType.createInterned(
|
return CirTypeAliasType.createInterned(
|
||||||
typeAliasId = type.classifierId,
|
typeAliasId = type.classifierId,
|
||||||
isMarkedNullable = type.isMarkedNullable,
|
isMarkedNullable = type.isMarkedNullable,
|
||||||
arguments = type.arguments.map { it.toCirTypeProjection() ?: return null },
|
arguments = type.arguments.map { toCirTypeProjection(it) ?: return null },
|
||||||
underlyingType = toCirClassOrTypeAliasTypeOrNull(typeAlias.underlyingType) ?: return null
|
underlyingType = toCirClassOrTypeAliasTypeOrNull(typeAlias.underlyingType) ?: return null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirProvided.ClassType.toCirClassTypeOrNull(): CirClassType? {
|
internal fun CirProvidedClassifiers.toCirClassTypeOrNull(type: CirProvided.ClassType): CirClassType? {
|
||||||
return CirClassType.createInterned(
|
return CirClassType.createInterned(
|
||||||
classId = this.classifierId,
|
classId = type.classifierId,
|
||||||
outerType = this.outerType?.let { it.toCirClassTypeOrNull() ?: return null },
|
outerType = type.outerType?.let { toCirClassTypeOrNull(it) ?: return null },
|
||||||
isMarkedNullable = this.isMarkedNullable,
|
isMarkedNullable = type.isMarkedNullable,
|
||||||
arguments = this.arguments.map { it.toCirTypeProjection() ?: return null },
|
arguments = type.arguments.map { toCirTypeProjection(it) ?: return null },
|
||||||
visibility = Visibilities.Public,
|
visibility = Visibilities.Public,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun CirProvided.TypeProjection.toCirTypeProjection(): CirTypeProjection? {
|
internal fun CirProvidedClassifiers.toCirTypeProjection(type: CirProvided.TypeProjection): CirTypeProjection? {
|
||||||
return when (this) {
|
return when (type) {
|
||||||
is CirProvided.StarTypeProjection -> CirStarTypeProjection
|
is CirProvided.StarTypeProjection -> CirStarTypeProjection
|
||||||
is CirProvided.RegularTypeProjection -> CirRegularTypeProjection(
|
is CirProvided.RegularTypeProjection -> toCirRegularTypeProjectionOrNull(type)
|
||||||
projectionKind = variance,
|
|
||||||
type = (type as? CirProvided.ClassType)?.toCirClassTypeOrNull() ?: return null
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun CirProvidedClassifiers.toCirRegularTypeProjectionOrNull(
|
||||||
|
projection: CirProvided.RegularTypeProjection
|
||||||
|
): CirRegularTypeProjection? {
|
||||||
|
return CirRegularTypeProjection(
|
||||||
|
projectionKind = projection.variance,
|
||||||
|
type = when (val type = projection.type) {
|
||||||
|
is CirProvided.ClassOrTypeAliasType -> toCirClassOrTypeAliasTypeOrNull(type) ?: return null
|
||||||
|
is CirProvided.TypeParameterType -> CirTypeParameterType.createInterned(type.index, type.isMarkedNullable)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ internal class SimpleCirSupertypesResolver(
|
|||||||
|
|
||||||
dependencies.classifier(type.classifierId)?.let { classifier ->
|
dependencies.classifier(type.classifierId)?.let { classifier ->
|
||||||
if (classifier is CirProvided.Class) {
|
if (classifier is CirProvided.Class) {
|
||||||
return supertypesFromProvidedClass(type, classifier)
|
return dependencies.supertypesFromProvidedClass(type, classifier)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return emptySet()
|
return emptySet()
|
||||||
@@ -47,9 +47,9 @@ internal class SimpleCirSupertypesResolver(
|
|||||||
.toSet()
|
.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun supertypesFromProvidedClass(type: CirClassType, classifier: CirProvided.Class): Set<CirClassType> {
|
private fun CirProvidedClassifiers.supertypesFromProvidedClass(type: CirClassType, classifier: CirProvided.Class): Set<CirClassType> {
|
||||||
return classifier.supertypes.filterIsInstance<CirProvided.ClassType>()
|
return classifier.supertypes.filterIsInstance<CirProvided.ClassType>()
|
||||||
.mapNotNull { superType -> superType.toCirClassTypeOrNull() }
|
.mapNotNull { superType -> toCirClassTypeOrNull(superType) }
|
||||||
.mapNotNull { superType -> buildSupertypeFromClassifierSupertype(type, superType) }
|
.mapNotNull { superType -> buildSupertypeFromClassifierSupertype(type, superType) }
|
||||||
.toSet()
|
.toSet()
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -23,6 +23,7 @@ internal class ClassOrTypeAliasTypeCommonizer(
|
|||||||
|
|
||||||
override fun invoke(values: List<CirClassOrTypeAliasType>): CirClassOrTypeAliasType? {
|
override fun invoke(values: List<CirClassOrTypeAliasType>): CirClassOrTypeAliasType? {
|
||||||
if (values.isEmpty()) return null
|
if (values.isEmpty()) return null
|
||||||
|
|
||||||
val expansions = values.map { it.expandedType() }
|
val expansions = values.map { it.expandedType() }
|
||||||
val isMarkedNullable = isMarkedNullableCommonizer.commonize(expansions.map { it.isMarkedNullable }) ?: return null
|
val isMarkedNullable = isMarkedNullableCommonizer.commonize(expansions.map { it.isMarkedNullable }) ?: return null
|
||||||
val arguments = TypeArgumentListCommonizer(typeCommonizer).commonize(values.map { it.arguments }) ?: return null
|
val arguments = TypeArgumentListCommonizer(typeCommonizer).commonize(values.map { it.arguments }) ?: return null
|
||||||
@@ -63,7 +64,8 @@ internal class ClassOrTypeAliasTypeCommonizer(
|
|||||||
arguments = arguments,
|
arguments = arguments,
|
||||||
isMarkedNullable = isMarkedNullable,
|
isMarkedNullable = isMarkedNullable,
|
||||||
underlyingType = classifiers.commonDependencies
|
underlyingType = classifiers.commonDependencies
|
||||||
.toCirClassOrTypeAliasTypeOrNull(dependencyClassifier.underlyingType) ?: return null
|
.toCirClassOrTypeAliasTypeOrNull(dependencyClassifier.underlyingType)
|
||||||
|
?.withParentArguments(arguments, isMarkedNullable) ?: return null
|
||||||
)
|
)
|
||||||
|
|
||||||
else -> Unit
|
else -> Unit
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class TypeAliasCommonizer(
|
|||||||
|
|
||||||
val typeParameters = TypeParameterListCommonizer(typeCommonizer).commonize(values.map { it.typeParameters }) ?: return null
|
val typeParameters = TypeParameterListCommonizer(typeCommonizer).commonize(values.map { it.typeParameters }) ?: return null
|
||||||
|
|
||||||
val underlyingType = typeCommonizer(values.map { it.underlyingType }) as? CirClassOrTypeAliasType ?: return null
|
val underlyingType = typeCommonizer.invoke(values.map { it.underlyingType }) as? CirClassOrTypeAliasType ?: return null
|
||||||
|
|
||||||
val visibility = VisibilityCommonizer.lowering().commonize(values) ?: return null
|
val visibility = VisibilityCommonizer.lowering().commonize(values) ?: return null
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -7,8 +7,8 @@ typealias C3 = C2 // TA lifted up as is
|
|||||||
|
|
||||||
typealias D = A // class/TA expanded to the same class at the RHS
|
typealias D = A // class/TA expanded to the same class at the RHS
|
||||||
typealias D2 = A // class/TA expanded to the same class at the RHS
|
typealias D2 = A // class/TA expanded to the same class at the RHS
|
||||||
typealias E = A // different TAs use common type from TA-chain
|
typealias E = B // different TAs use common type from TA-chain
|
||||||
typealias E2 = A // different TAs use common type from TA-chain
|
typealias E2 = B // different TAs use common type from TA-chain
|
||||||
|
|
||||||
typealias F = List<String> // parameterized type at the RHS
|
typealias F = List<String> // parameterized type at the RHS
|
||||||
typealias H<T> = List<T> // TA with own parameters
|
typealias H<T> = List<T> // TA with own parameters
|
||||||
|
|||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.commonizer.hierarchical
|
||||||
|
|
||||||
|
|
||||||
|
class ParameterizedTypesCommonizationTest {
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user