TypeParameterDescriptor propagation to CapturedTypeConstructor
This commit is contained in:
+1
-1
@@ -320,7 +320,7 @@ class ConstraintSystemBuilderImpl : ConstraintSystem.Builder {
|
|||||||
else {
|
else {
|
||||||
constrainingTypeProjection
|
constrainingTypeProjection
|
||||||
}
|
}
|
||||||
val capturedType = createCapturedType(typeProjection)
|
val capturedType = createCapturedType(typeProjection, typeVariable.originalTypeParameter)
|
||||||
addBound(typeVariable, capturedType, EXACT_BOUND, constraintContext)
|
addBound(typeVariable, capturedType, EXACT_BOUND, constraintContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -87,8 +87,8 @@ private fun ConstraintSystemBuilderImpl.generateNewBound(bound: Bound, substitut
|
|||||||
|
|
||||||
val substitutedType = when (substitution.kind) {
|
val substitutedType = when (substitution.kind) {
|
||||||
EXACT_BOUND -> substitution.constrainingType
|
EXACT_BOUND -> substitution.constrainingType
|
||||||
UPPER_BOUND -> CapturedType(TypeProjectionImpl(Variance.OUT_VARIANCE, substitution.constrainingType))
|
UPPER_BOUND -> CapturedType(TypeProjectionImpl(Variance.OUT_VARIANCE, substitution.constrainingType), substitution.typeVariable.originalTypeParameter)
|
||||||
LOWER_BOUND -> CapturedType(TypeProjectionImpl(Variance.IN_VARIANCE, substitution.constrainingType))
|
LOWER_BOUND -> CapturedType(TypeProjectionImpl(Variance.IN_VARIANCE, substitution.constrainingType), substitution.typeVariable.originalTypeParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
val newTypeProjection = TypeProjectionImpl(substitutedType)
|
val newTypeProjection = TypeProjectionImpl(substitutedType)
|
||||||
|
|||||||
+1
-1
@@ -84,7 +84,7 @@ class CapturedTypeApproximationTest() : KotlinLiteFixture() {
|
|||||||
fun createTestSubstitutor(testSubstitution: Map<TypeParameterDescriptor, TypeProjection>): TypeSubstitutor {
|
fun createTestSubstitutor(testSubstitution: Map<TypeParameterDescriptor, TypeProjection>): TypeSubstitutor {
|
||||||
val substitutionContext = testSubstitution.map {
|
val substitutionContext = testSubstitution.map {
|
||||||
val (typeParameter, typeProjection) = it
|
val (typeParameter, typeProjection) = it
|
||||||
typeParameter.typeConstructor to TypeProjectionImpl(createCapturedType(typeProjection))
|
typeParameter.typeConstructor to TypeProjectionImpl(createCapturedType(typeProjection, typeParameter))
|
||||||
}.toMap()
|
}.toMap()
|
||||||
return TypeSubstitutor.create(substitutionContext)
|
return TypeSubstitutor.create(substitutionContext)
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-6
@@ -25,7 +25,8 @@ import org.jetbrains.kotlin.types.Variance.OUT_VARIANCE
|
|||||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||||
|
|
||||||
class CapturedTypeConstructor(
|
class CapturedTypeConstructor(
|
||||||
val typeProjection: TypeProjection
|
val typeProjection: TypeProjection,
|
||||||
|
val typeParameterDescriptor: TypeParameterDescriptor
|
||||||
): TypeConstructor {
|
): TypeConstructor {
|
||||||
init {
|
init {
|
||||||
assert(typeProjection.projectionKind != Variance.INVARIANT) {
|
assert(typeProjection.projectionKind != Variance.INVARIANT) {
|
||||||
@@ -47,7 +48,7 @@ class CapturedTypeConstructor(
|
|||||||
|
|
||||||
override fun isDenotable() = false
|
override fun isDenotable() = false
|
||||||
|
|
||||||
override fun getDeclarationDescriptor() = null
|
override fun getDeclarationDescriptor() = typeParameterDescriptor
|
||||||
|
|
||||||
override fun getAnnotations() = Annotations.EMPTY
|
override fun getAnnotations() = Annotations.EMPTY
|
||||||
|
|
||||||
@@ -57,13 +58,14 @@ class CapturedTypeConstructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CapturedType(
|
class CapturedType(
|
||||||
private val typeProjection: TypeProjection
|
private val typeProjection: TypeProjection,
|
||||||
|
private val typeParameterDescriptor: TypeParameterDescriptor
|
||||||
): DelegatingType(), SubtypingRepresentatives {
|
): DelegatingType(), SubtypingRepresentatives {
|
||||||
|
|
||||||
private val delegateType = run {
|
private val delegateType = run {
|
||||||
val scope = ErrorUtils.createErrorScope(
|
val scope = ErrorUtils.createErrorScope(
|
||||||
"No member resolution should be done on captured type, it used only during constraint system resolution", true)
|
"No member resolution should be done on captured type, it used only during constraint system resolution", true)
|
||||||
KotlinTypeImpl.create(Annotations.EMPTY, CapturedTypeConstructor(typeProjection), false, listOf(), scope)
|
KotlinTypeImpl.create(Annotations.EMPTY, CapturedTypeConstructor(typeProjection, typeParameterDescriptor), false, listOf(), scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDelegate(): KotlinType = delegateType
|
override fun getDelegate(): KotlinType = delegateType
|
||||||
@@ -93,7 +95,8 @@ class CapturedType(
|
|||||||
override fun toString() = "Captured($typeProjection)"
|
override fun toString() = "Captured($typeProjection)"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createCapturedType(typeProjection: TypeProjection): KotlinType = CapturedType(typeProjection)
|
fun createCapturedType(typeProjection: TypeProjection, typeParameterDescriptor: TypeParameterDescriptor): KotlinType
|
||||||
|
= CapturedType(typeProjection, typeParameterDescriptor)
|
||||||
|
|
||||||
fun KotlinType.isCaptured(): Boolean = constructor is CapturedTypeConstructor
|
fun KotlinType.isCaptured(): Boolean = constructor is CapturedTypeConstructor
|
||||||
|
|
||||||
@@ -125,5 +128,5 @@ private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeP
|
|||||||
TypeProjectionImpl(this@createCapturedIfNeeded.type)
|
TypeProjectionImpl(this@createCapturedIfNeeded.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
return TypeProjectionImpl(createCapturedType(this))
|
return TypeProjectionImpl(createCapturedType(this, typeParameterDescriptor))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user