Rearranged code in isCastErased()

This commit is contained in:
Evgeny Gerashchenko
2012-11-06 19:25:48 +04:00
parent 5b61785306
commit 3318804030
@@ -283,7 +283,6 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
* 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 actualType, JetType targetType, JetTypeChecker typeChecker) { public static boolean isCastErased(JetType actualType, JetType targetType, JetTypeChecker typeChecker) {
if (!(targetType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) { if (!(targetType.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) {
// TODO: what if it is TypeParameterDescriptor? // TODO: what if it is TypeParameterDescriptor?
return false; return false;
@@ -294,22 +293,23 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return false; return false;
} }
List<TypeParameterDescriptor> actualTypeParameters = actualType.getConstructor().getParameters();
{ {
Multimap<TypeConstructor, TypeProjection> typeSubstitutionMap = Multimap<TypeConstructor, TypeProjection> typeSubstitutionMap =
SubstitutionUtils.buildDeepSubstitutionMultimap(targetType); SubstitutionUtils.buildDeepSubstitutionMultimap(targetType);
for (int i = 0; i < actualType.getConstructor().getParameters().size(); ++i) { for (int i = 0; i < actualTypeParameters.size(); i++) {
TypeProjection actualTypeParameter = actualType.getArguments().get(i); TypeProjection actualTypeArgument = actualType.getArguments().get(i);
TypeParameterDescriptor subjectTypeParameterDescriptor = actualType.getConstructor().getParameters().get(i); TypeParameterDescriptor actualTypeParameter = actualTypeParameters.get(i);
if (subjectTypeParameterDescriptor.isReified()) { if (actualTypeParameter.isReified()) {
continue; continue;
} }
Collection<TypeProjection> subst = typeSubstitutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); Collection<TypeProjection> substituted = typeSubstitutionMap.get(actualTypeParameter.getTypeConstructor());
for (TypeProjection proj : subst) { for (TypeProjection substitutedProjection : substituted) {
//if (!proj.getType().equals(actualTypeParameter.getType())) { //if (!substitutedProjection.getType().equals(actualTypeArgument.getType())) {
if (!typeChecker.isSubtypeOf(actualTypeParameter.getType(), proj.getType())) { if (!typeChecker.isSubtypeOf(actualTypeArgument.getType(), substitutedProjection.getType())) { // TODO hides error
return true; return true;
} }
} }
@@ -317,33 +317,32 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
} }
{ {
JetType targetTypeClerared = TypeUtils.makeUnsubstitutedType( JetType targetTypeCleared = TypeUtils.makeUnsubstitutedType(
(ClassDescriptor) targetType.getConstructor().getDeclarationDescriptor(), null); (ClassDescriptor) targetType.getConstructor().getDeclarationDescriptor(), null);
Multimap<TypeConstructor, TypeProjection> clearTypeSubstitutionMap = Multimap<TypeConstructor, TypeProjection> clearTypeSubstitutionMap =
SubstitutionUtils.buildDeepSubstitutionMultimap(targetTypeClerared); SubstitutionUtils.buildDeepSubstitutionMultimap(targetTypeCleared);
Set<JetType> clearSubstituted = new HashSet<JetType>(); Set<JetType> clearSubstituted = new HashSet<JetType>();
for (int i = 0; i < actualType.getConstructor().getParameters().size(); ++i) { for (TypeParameterDescriptor actualTypeParameter : actualTypeParameters) {
TypeParameterDescriptor subjectTypeParameterDescriptor = actualType.getConstructor().getParameters().get(i); Collection<TypeProjection> substituted = clearTypeSubstitutionMap.get(actualTypeParameter.getTypeConstructor());
for (TypeProjection substitutedProjection : substituted) {
Collection<TypeProjection> subst = clearTypeSubstitutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); clearSubstituted.add(substitutedProjection.getType());
for (TypeProjection proj : subst) {
clearSubstituted.add(proj.getType());
} }
} }
for (int i = 0; i < targetType.getConstructor().getParameters().size(); ++i) { List<TypeParameterDescriptor> targetTypeParameters = targetType.getConstructor().getParameters();
TypeParameterDescriptor typeParameter = targetType.getConstructor().getParameters().get(i); for (int i = 0; i < targetTypeParameters.size(); i++) {
TypeProjection typeProjection = targetType.getArguments().get(i); TypeParameterDescriptor typeParameter = targetTypeParameters.get(i);
if (typeParameter.isReified()) { if (typeParameter.isReified()) {
continue; continue;
} }
// "is List<*>" // "is List<*>"
if (typeProjection.equals(SubstitutionUtils.makeStarProjection(typeParameter))) { TypeProjection typeArgument = targetType.getArguments().get(i);
if (typeArgument.equals(SubstitutionUtils.makeStarProjection(typeParameter))) {
continue; continue;
} }