Approximate captured types in contravariant positions properly
^KT-43802 Fixed
This commit is contained in:
@@ -85,6 +85,15 @@ abstract class TypeConstructorSubstitution : TypeSubstitution() {
|
||||
}
|
||||
}
|
||||
|
||||
class SubstitutionWithCapturedTypeApproximation(substitution: TypeSubstitution) : DelegatedTypeSubstitution(substitution) {
|
||||
override fun approximateCapturedTypes() = true
|
||||
}
|
||||
|
||||
class SubstitutionWithContravariantCapturedTypeApproximation(substitution: TypeSubstitution) : DelegatedTypeSubstitution(substitution) {
|
||||
override fun approximateCapturedTypes() = true
|
||||
override fun approximateContravariantCapturedTypes() = true
|
||||
}
|
||||
|
||||
class IndexedParametersSubstitution(
|
||||
val parameters: Array<TypeParameterDescriptor>,
|
||||
val arguments: Array<TypeProjection>,
|
||||
|
||||
@@ -67,6 +67,29 @@ public class TypeSubstitutor implements TypeSubstitutorMarker {
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public TypeSubstitutor replaceWithContravariantApproximatingSubstitution() {
|
||||
if (substitution instanceof SubstitutionWithCapturedTypeApproximation) {
|
||||
return new TypeSubstitutor(
|
||||
new SubstitutionWithContravariantCapturedTypeApproximation(
|
||||
((SubstitutionWithCapturedTypeApproximation) substitution).getSubstitution()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if (substitution instanceof IndexedParametersSubstitution && !substitution.approximateContravariantCapturedTypes()) {
|
||||
return new TypeSubstitutor(
|
||||
new IndexedParametersSubstitution(
|
||||
((IndexedParametersSubstitution) substitution).getParameters(),
|
||||
((IndexedParametersSubstitution) substitution).getArguments(),
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static TypeSubstitutor createChainedSubstitutor(@NotNull TypeSubstitution first, @NotNull TypeSubstitution second) {
|
||||
return create(DisjointKeysUnionTypeSubstitution.create(first, second));
|
||||
|
||||
Reference in New Issue
Block a user