From 33188040308a4f437dd25d416b0ceecf18201055 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 6 Nov 2012 19:25:48 +0400 Subject: [PATCH] Rearranged code in isCastErased() --- .../BasicExpressionTypingVisitor.java | 41 +++++++++---------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 7f503d413c7..bd22c7d6f2b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -283,7 +283,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { * It is an error in "is" statement and warning in "as". */ public static boolean isCastErased(JetType actualType, JetType targetType, JetTypeChecker typeChecker) { - if (!(targetType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) { // TODO: what if it is TypeParameterDescriptor? return false; @@ -294,22 +293,23 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { return false; } + List actualTypeParameters = actualType.getConstructor().getParameters(); { Multimap typeSubstitutionMap = SubstitutionUtils.buildDeepSubstitutionMultimap(targetType); - for (int i = 0; i < actualType.getConstructor().getParameters().size(); ++i) { - TypeProjection actualTypeParameter = actualType.getArguments().get(i); - TypeParameterDescriptor subjectTypeParameterDescriptor = actualType.getConstructor().getParameters().get(i); + for (int i = 0; i < actualTypeParameters.size(); i++) { + TypeProjection actualTypeArgument = actualType.getArguments().get(i); + TypeParameterDescriptor actualTypeParameter = actualTypeParameters.get(i); - if (subjectTypeParameterDescriptor.isReified()) { + if (actualTypeParameter.isReified()) { continue; } - Collection subst = typeSubstitutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); - for (TypeProjection proj : subst) { - //if (!proj.getType().equals(actualTypeParameter.getType())) { - if (!typeChecker.isSubtypeOf(actualTypeParameter.getType(), proj.getType())) { + Collection substituted = typeSubstitutionMap.get(actualTypeParameter.getTypeConstructor()); + for (TypeProjection substitutedProjection : substituted) { + //if (!substitutedProjection.getType().equals(actualTypeArgument.getType())) { + if (!typeChecker.isSubtypeOf(actualTypeArgument.getType(), substitutedProjection.getType())) { // TODO hides error return true; } } @@ -317,33 +317,32 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { } { - JetType targetTypeClerared = TypeUtils.makeUnsubstitutedType( + JetType targetTypeCleared = TypeUtils.makeUnsubstitutedType( (ClassDescriptor) targetType.getConstructor().getDeclarationDescriptor(), null); Multimap clearTypeSubstitutionMap = - SubstitutionUtils.buildDeepSubstitutionMultimap(targetTypeClerared); + SubstitutionUtils.buildDeepSubstitutionMultimap(targetTypeCleared); Set clearSubstituted = new HashSet(); - for (int i = 0; i < actualType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor subjectTypeParameterDescriptor = actualType.getConstructor().getParameters().get(i); - - Collection subst = clearTypeSubstitutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); - for (TypeProjection proj : subst) { - clearSubstituted.add(proj.getType()); + for (TypeParameterDescriptor actualTypeParameter : actualTypeParameters) { + Collection substituted = clearTypeSubstitutionMap.get(actualTypeParameter.getTypeConstructor()); + for (TypeProjection substitutedProjection : substituted) { + clearSubstituted.add(substitutedProjection.getType()); } } - for (int i = 0; i < targetType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor typeParameter = targetType.getConstructor().getParameters().get(i); - TypeProjection typeProjection = targetType.getArguments().get(i); + List targetTypeParameters = targetType.getConstructor().getParameters(); + for (int i = 0; i < targetTypeParameters.size(); i++) { + TypeParameterDescriptor typeParameter = targetTypeParameters.get(i); if (typeParameter.isReified()) { continue; } // "is List<*>" - if (typeProjection.equals(SubstitutionUtils.makeStarProjection(typeParameter))) { + TypeProjection typeArgument = targetType.getArguments().get(i); + if (typeArgument.equals(SubstitutionUtils.makeStarProjection(typeParameter))) { continue; }