From b3311f717dbc7cff86c9442781cc9f2c8e5d7c88 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 8 Nov 2012 16:43:52 +0400 Subject: [PATCH] Deep substitution now doesn't lose variance info. --- .../jetbrains/jet/lang/types/SubstitutionUtils.java | 9 ++++----- .../org/jetbrains/jet/lang/types/TypeSubstitutor.java | 10 ++++++++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java index 939a931fe19..a54de67adae 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java @@ -71,14 +71,13 @@ public class SubstitutionUtils { for (int i = 0; i < arguments.size(); 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; - TypeProjection substitutedTypeProjection = new TypeProjection(argument.getProjectionKind(), substitute); - substitution.put(typeParameterDescriptor.getTypeConstructor(), substitutedTypeProjection); + substitution.put(parameter.getTypeConstructor(), substitute); if (fullSubstitution != null) { - fullSubstitution.put(typeParameterDescriptor.getTypeConstructor(), substitutedTypeProjection); + fullSubstitution.put(parameter.getTypeConstructor(), substitute); } } if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java index 3ef635d6e38..a4093b1a7ae 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java @@ -125,12 +125,18 @@ public class TypeSubstitutor { @Nullable 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()) { - return type; + return typeProjection; } try { - return unsafeSubstitute(new TypeProjection(howThisTypeIsUsed, type), 0).getType(); + return unsafeSubstitute(typeProjection, 0); } catch (SubstitutionException e) { return null; }