Deep substitution now doesn't lose variance info.
This commit is contained in:
@@ -71,14 +71,13 @@ public class SubstitutionUtils {
|
|||||||
|
|
||||||
for (int i = 0; i < arguments.size(); i++) {
|
for (int i = 0; i < arguments.size(); i++) {
|
||||||
TypeProjection argument = arguments.get(i);
|
TypeProjection argument = arguments.get(i);
|
||||||
TypeParameterDescriptor typeParameterDescriptor = parameters.get(i);
|
TypeParameterDescriptor parameter = parameters.get(i);
|
||||||
|
|
||||||
JetType substitute = substitutor.substitute(argument.getType(), Variance.INVARIANT);
|
TypeProjection substitute = substitutor.substitute(argument);
|
||||||
assert substitute != null;
|
assert substitute != null;
|
||||||
TypeProjection substitutedTypeProjection = new TypeProjection(argument.getProjectionKind(), substitute);
|
substitution.put(parameter.getTypeConstructor(), substitute);
|
||||||
substitution.put(typeParameterDescriptor.getTypeConstructor(), substitutedTypeProjection);
|
|
||||||
if (fullSubstitution != null) {
|
if (fullSubstitution != null) {
|
||||||
fullSubstitution.put(typeParameterDescriptor.getTypeConstructor(), substitutedTypeProjection);
|
fullSubstitution.put(parameter.getTypeConstructor(), substitute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return;
|
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return;
|
||||||
|
|||||||
@@ -125,12 +125,18 @@ public class TypeSubstitutor {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetType substitute(@NotNull JetType type, @NotNull Variance howThisTypeIsUsed) {
|
public JetType substitute(@NotNull JetType type, @NotNull Variance howThisTypeIsUsed) {
|
||||||
|
TypeProjection projection = substitute(new TypeProjection(howThisTypeIsUsed, type));
|
||||||
|
return projection == null ? null : projection.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public TypeProjection substitute(@NotNull TypeProjection typeProjection) {
|
||||||
if (isEmpty()) {
|
if (isEmpty()) {
|
||||||
return type;
|
return typeProjection;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return unsafeSubstitute(new TypeProjection(howThisTypeIsUsed, type), 0).getType();
|
return unsafeSubstitute(typeProjection, 0);
|
||||||
} catch (SubstitutionException e) {
|
} catch (SubstitutionException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user