Minor. Turn TypeBasedStarProjectionImpl into StarProjectionForAbsentTypeParameter
It's needed to avoid abusing of the class Star projections should be created based on the relevant type parameter whenever it's possible
This commit is contained in:
committed by
Dmitry Savvinov
parent
579838cb4e
commit
ffaca279bc
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.types
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
@@ -44,24 +45,27 @@ fun TypeParameterDescriptor.starProjectionType(): KotlinType {
|
||||
val classDescriptor = this.containingDeclaration as ClassifierDescriptorWithTypeParameters
|
||||
val typeParameters = classDescriptor.typeConstructor.parameters.map { it.typeConstructor }
|
||||
return TypeSubstitutor.create(
|
||||
object : TypeConstructorSubstitution() {
|
||||
override fun get(key: TypeConstructor) =
|
||||
if (key in typeParameters)
|
||||
TypeUtils.makeStarProjection(key.declarationDescriptor as TypeParameterDescriptor)
|
||||
else null
|
||||
object : TypeConstructorSubstitution() {
|
||||
override fun get(key: TypeConstructor) =
|
||||
if (key in typeParameters)
|
||||
TypeUtils.makeStarProjection(key.declarationDescriptor as TypeParameterDescriptor)
|
||||
else null
|
||||
|
||||
}
|
||||
}
|
||||
).substitute(this.upperBounds.first(), Variance.OUT_VARIANCE) ?: builtIns.defaultBound
|
||||
}
|
||||
|
||||
class TypeBasedStarProjectionImpl(
|
||||
private val _type: KotlinType
|
||||
// It should only be used in rare cases when type parameter for the relevant argument is not available
|
||||
class StarProjectionForAbsentTypeParameter(
|
||||
kotlinBuiltIns: KotlinBuiltIns
|
||||
) : TypeProjectionBase() {
|
||||
private val nullableAnyType: KotlinType = kotlinBuiltIns.nullableAnyType
|
||||
|
||||
override fun isStarProjection() = true
|
||||
|
||||
override fun getProjectionKind() = Variance.OUT_VARIANCE
|
||||
|
||||
override fun getType() = _type
|
||||
override fun getType() = nullableAnyType
|
||||
|
||||
@TypeRefinement
|
||||
override fun refine(kotlinTypeRefiner: KotlinTypeRefiner): TypeProjection = this
|
||||
|
||||
+1
-1
@@ -241,7 +241,7 @@ class TypeDeserializer(
|
||||
private fun typeArgument(parameter: TypeParameterDescriptor?, typeArgumentProto: ProtoBuf.Type.Argument): TypeProjection {
|
||||
if (typeArgumentProto.projection == ProtoBuf.Type.Argument.Projection.STAR) {
|
||||
return if (parameter == null)
|
||||
TypeBasedStarProjectionImpl(c.components.moduleDescriptor.builtIns.nullableAnyType)
|
||||
StarProjectionForAbsentTypeParameter(c.components.moduleDescriptor.builtIns)
|
||||
else
|
||||
StarProjectionImpl(parameter)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user