Extracted methods from isCastErased.

This commit is contained in:
Evgeny Gerashchenko
2012-11-08 19:00:44 +04:00
parent e691a0bc93
commit 04eefb4244
@@ -283,7 +283,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
* Check if assignment from supertype to subtype is erased. * Check if assignment from supertype to subtype is erased.
* It is an error in "is" statement and warning in "as". * It is an error in "is" statement and warning in "as".
*/ */
public static boolean isCastErased(JetType supertype, JetType subtype, JetTypeChecker typeChecker) { public static boolean isCastErased(@NotNull JetType supertype, @NotNull JetType subtype, @NotNull JetTypeChecker typeChecker) {
if (!(subtype.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) { if (!(subtype.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
// TODO: what if it is TypeParameterDescriptor? // TODO: what if it is TypeParameterDescriptor?
return false; return false;
@@ -294,8 +294,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return false; return false;
} }
return hasDowncastsInTypeArguments(supertype, subtype, typeChecker) || hasErasedTypeArguments(supertype, subtype);
}
private static boolean hasDowncastsInTypeArguments(
@NotNull JetType supertype,
@NotNull JetType subtype,
@NotNull JetTypeChecker typeChecker
) {
List<TypeParameterDescriptor> superParameters = supertype.getConstructor().getParameters(); List<TypeParameterDescriptor> superParameters = supertype.getConstructor().getParameters();
{
Multimap<TypeConstructor, TypeProjection> subtypeSubstitutionMap = Multimap<TypeConstructor, TypeProjection> subtypeSubstitutionMap =
SubstitutionUtils.buildDeepSubstitutionMultimap(subtype); SubstitutionUtils.buildDeepSubstitutionMultimap(subtype);
@@ -322,9 +329,14 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
} }
} }
return false;
} }
{ private static boolean hasErasedTypeArguments(
@NotNull JetType supertype,
@NotNull JetType subtype
) {
JetType subtypeCleared = TypeUtils.makeUnsubstitutedType( JetType subtypeCleared = TypeUtils.makeUnsubstitutedType(
(ClassDescriptor) subtype.getConstructor().getDeclarationDescriptor(), null); (ClassDescriptor) subtype.getConstructor().getDeclarationDescriptor(), null);
@@ -333,6 +345,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
Set<JetType> clearSubstituted = new HashSet<JetType>(); Set<JetType> clearSubstituted = new HashSet<JetType>();
List<TypeParameterDescriptor> superParameters = supertype.getConstructor().getParameters();
for (TypeParameterDescriptor superTypeParameter : superParameters) { for (TypeParameterDescriptor superTypeParameter : superParameters) {
Collection<TypeProjection> substituted = clearTypeSubstitutionMap.get(superTypeParameter.getTypeConstructor()); Collection<TypeProjection> substituted = clearTypeSubstitutionMap.get(superTypeParameter.getTypeConstructor());
for (TypeProjection substitutedProjection : substituted) { for (TypeProjection substitutedProjection : substituted) {
@@ -359,7 +372,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return true; return true;
} }
} }
}
return false; return false;
} }