KT-15748 Type alias constructor return type should have a corresponding abbreviation
This commit is contained in:
+11
-6
@@ -20,9 +20,7 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
interface TypeAliasConstructorDescriptor : ConstructorDescriptor {
|
||||
val underlyingConstructorDescriptor: ClassConstructorDescriptor
|
||||
@@ -122,15 +120,22 @@ class TypeAliasConstructorDescriptorImpl private constructor(
|
||||
val valueParameters = FunctionDescriptorImpl.getSubstitutedValueParameters(typeAliasConstructor, constructor.valueParameters, substitutor, false, false)
|
||||
?: return null
|
||||
|
||||
val returnType = substitutor.substitute(constructor.returnType, Variance.INVARIANT)
|
||||
?: return null
|
||||
val returnType = run {
|
||||
val returnTypeNoAbbreviation = substitutor.substitute(constructor.returnType, Variance.INVARIANT)
|
||||
?: return null
|
||||
val abbreviation = typeAliasDescriptor.defaultType
|
||||
if (returnTypeNoAbbreviation is SimpleType && abbreviation is SimpleType)
|
||||
returnTypeNoAbbreviation.withAbbreviation(abbreviation)
|
||||
else
|
||||
returnTypeNoAbbreviation
|
||||
}
|
||||
|
||||
val receiverParameterType =
|
||||
if (withDispatchReceiver) null
|
||||
else constructor.dispatchReceiverParameter?.let { substitutor.safeSubstitute(it.type, Variance.INVARIANT) }
|
||||
|
||||
val dispatchReceiver =
|
||||
if (withDispatchReceiver) constructor.dispatchReceiverParameter?.let { it.substitute(substitutor) }
|
||||
if (withDispatchReceiver) constructor.dispatchReceiverParameter?.substitute(substitutor)
|
||||
else null
|
||||
|
||||
typeAliasConstructor.initialize(
|
||||
|
||||
@@ -43,6 +43,7 @@ class AbbreviatedType(override val delegate: SimpleType, val abbreviation: Simpl
|
||||
}
|
||||
|
||||
fun KotlinType.getAbbreviatedType(): AbbreviatedType? = unwrap() as? AbbreviatedType
|
||||
fun KotlinType.getAbbreviation(): SimpleType? = getAbbreviatedType()?.abbreviation
|
||||
|
||||
fun SimpleType.withAbbreviation(abbreviatedType: SimpleType): SimpleType {
|
||||
if (isError) return this
|
||||
|
||||
@@ -229,11 +229,21 @@ public class TypeSubstitutor {
|
||||
return originalProjection;
|
||||
}
|
||||
|
||||
KotlinType substitutedAbbreviation = null;
|
||||
SimpleType abbreviation = SpecialTypesKt.getAbbreviation(type);
|
||||
if (abbreviation != null) {
|
||||
substitutedAbbreviation = substitute(abbreviation, Variance.INVARIANT);
|
||||
}
|
||||
|
||||
List<TypeProjection> substitutedArguments = substituteTypeArguments(
|
||||
type.getConstructor().getParameters(), type.getArguments(), recursionDepth);
|
||||
|
||||
KotlinType substitutedType =
|
||||
TypeSubstitutionKt.replace(type, substitutedArguments, substitution.filterAnnotations(type.getAnnotations()));
|
||||
if (substitutedType instanceof SimpleType && substitutedAbbreviation instanceof SimpleType) {
|
||||
substitutedType = SpecialTypesKt.withAbbreviation((SimpleType) substitutedType, (SimpleType) substitutedAbbreviation);
|
||||
}
|
||||
|
||||
return new TypeProjectionImpl(projectionKind, substitutedType);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user