diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 785e9abbae6..da7edd9d6fe 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -16,7 +16,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Modifier; import java.util.Collection; import java.util.Iterator; -import java.util.List; import static org.jetbrains.jet.lang.diagnostics.Severity.ERROR; import static org.jetbrains.jet.lang.diagnostics.Severity.WARNING; @@ -276,10 +275,7 @@ public interface Errors { ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_TUPLE_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "Type mismatch: subject is of type {0} but the pattern is of type Tuple{1}"); // TODO: message ParameterizedDiagnosticFactory2 TYPE_MISMATCH_IN_BINDING_PATTERN = ParameterizedDiagnosticFactory2.create(ERROR, "{0} must be a supertype of {1}. Use 'is' to match against {0}"); ParameterizedDiagnosticFactory2 INCOMPATIBLE_TYPES = ParameterizedDiagnosticFactory2.create(ERROR, "Incompatible types: {0} and {1}"); - - ParameterizedDiagnosticFactory1 CANNOT_CHECK_FOR_ERASED = ParameterizedDiagnosticFactory1.create(ERROR, "Cannot check for instance of erased type: {0}"); - ParameterizedDiagnosticFactory2 UNCHECKED_CAST = ParameterizedDiagnosticFactory2.create(WARNING, "Unchecked cast: {0} to {1}"); - + ParameterizedDiagnosticFactory3> INCONSISTENT_TYPE_PARAMETER_VALUES = new ParameterizedDiagnosticFactory3>(ERROR, "Type parameter {0} of {1} has inconsistent values: {2}") { @Override protected String makeMessageForA(@NotNull TypeParameterDescriptor typeParameterDescriptor) { 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 10c3ca8cae5..0446105d479 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 @@ -1,7 +1,6 @@ package org.jetbrains.jet.lang.types.expressions; import com.google.common.collect.Lists; -import com.google.common.collect.Multimap; import com.intellij.lang.ASTNode; import com.intellij.psi.PsiElement; import com.intellij.psi.tree.IElementType; @@ -9,7 +8,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.JetNodeTypes; import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.calls.CallMaker; @@ -247,58 +245,10 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { else { if (typeChecker.isSubtypeOf(actualType, targetType)) { context.trace.report(USELESS_CAST.on(expression, expression.getOperationSign())); - } else { - if (isCastErased(actualType, targetType)) { - context.trace.report(Errors.UNCHECKED_CAST.on(expression, actualType, targetType)); - } } } } - /** - * Check if assignment from ActualType to TargetType is erased. - * It is an error in "is" statement and warning in "as". - */ - public static boolean isCastErased(JetType actualType, JetType targetType) { - - JetType targetTypeClerared = TypeUtils.makeUnsubstitutedType( - (ClassDescriptor) targetType.getConstructor().getDeclarationDescriptor(), null); - - Multimap clearTypeSubstitutionMap = - TypeUtils.buildDeepSubstitutionMultimap(targetTypeClerared); - - 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 (int i = 0; i < targetType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor typeParameter = targetType.getConstructor().getParameters().get(i); - TypeProjection typeProjection = targetType.getArguments().get(i); - - if (typeParameter.isReified()) { - continue; - } - - // "is List<*>" - if (typeProjection.equals(TypeUtils.makeStarProjection(typeParameter))) { - continue; - } - - // if parameter is mapped to nothing then it is erased - if (!clearSubstituted.contains(typeParameter.getDefaultType())) { - return true; - } - } - return false; - } - @Override public JetType visitTupleExpression(JetTupleExpression expression, ExpressionTypingContext context) { List entries = expression.getEntries(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java index 9a7c4d968c3..943343f4d70 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java @@ -1,14 +1,11 @@ package org.jetbrains.jet.lang.types.expressions; -import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.Ref; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; -import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue; @@ -20,7 +17,8 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor; import org.jetbrains.jet.lang.resolve.scopes.receivers.TransientReceiver; import org.jetbrains.jet.lang.types.*; -import java.util.*; +import java.util.List; +import java.util.Set; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.ensureBooleanResultWithCustomSubject; @@ -247,9 +245,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { } } - /* - * (a: SubjectType) is Type - */ private void checkTypeCompatibility(@Nullable JetType type, @NotNull JetType subjectType, @NotNull JetElement reportErrorOn) { // TODO : Take auto casts into account? if (type == null) { @@ -258,29 +253,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { if (TypeUtils.intersect(context.semanticServices.getTypeChecker(), Sets.newHashSet(type, subjectType)) == null) { // context.trace.getErrorHandler().genericError(reportErrorOn.getNode(), "Incompatible types: " + type + " and " + subjectType); context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType)); - return; - } - - { - // check parameters compatible - Multimap typeSubstritutionMap = TypeUtils.buildDeepSubstitutionMultimap(type); - - for (int i = 0; i < subjectType.getConstructor().getParameters().size(); ++i) { - TypeParameterDescriptor subjectTypeParameterDescriptor = subjectType.getConstructor().getParameters().get(i); - TypeProjection subjectParameterType = subjectType.getArguments().get(i); - - Collection xxy = typeSubstritutionMap.get(subjectTypeParameterDescriptor.getTypeConstructor()); - for (TypeProjection proj : xxy) { - if (!context.semanticServices.getTypeChecker().isSubtypeOf(subjectParameterType.getType(), proj.getType())) { - context.trace.report(INCOMPATIBLE_TYPES.on(reportErrorOn, type, subjectType)); - continue; - } - } - } - } - - if (BasicExpressionTypingVisitor.isCastErased(subjectType, type)) { - context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(reportErrorOn, type)); } } diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet deleted file mode 100644 index bff067d20ee..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedError.jet +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.List; -import java.util.Collection; - -fun ff(c: Collection) = c as List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet deleted file mode 100644 index 341f370d108..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedFine.jet +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.List; -import java.util.Collection; - -fun ff(c: Collection) = c as List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet deleted file mode 100644 index b9c2faf0d9a..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedStar.jet +++ /dev/null @@ -1,4 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = l as List<*> - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet b/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet deleted file mode 100644 index a55f6b7d58b..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/AsErasedWarning.jet +++ /dev/null @@ -1,3 +0,0 @@ -import java.util.List; - -fun ff(a: Any) = a as List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet deleted file mode 100644 index 7f32b79eba2..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllow.jet +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.Collection; -import java.util.List; - -fun ff(l: Collection) = l is List - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet deleted file mode 100644 index d1694229dc6..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedAllowParameterSubtype.jet +++ /dev/null @@ -1,9 +0,0 @@ -import java.util.Collection; -import java.util.List; - -open class A - -class B : A - -fun ff(l: Collection) = l is List - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet deleted file mode 100644 index eb3b402ccc7..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromAny.jet +++ /dev/null @@ -1,3 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = l is List diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet deleted file mode 100644 index a70b5932999..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedDisallowFromParameter.jet +++ /dev/null @@ -1,5 +0,0 @@ -import java.util.List; -import java.util.Collection; - -fun ff(l: Collection) = l is List - diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet deleted file mode 100644 index 404d8f8f3b0..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsErasedStar.jet +++ /dev/null @@ -1,3 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = l is List<*> diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet deleted file mode 100644 index 247196d6e84..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsReified.jet +++ /dev/null @@ -1,3 +0,0 @@ -class MyList - -fun ff(a: Any) = a is MyList diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet deleted file mode 100644 index 9abceb5f1e6..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsReifiedDisallow.jet +++ /dev/null @@ -1,3 +0,0 @@ -class MyList - -fun ff(l: MyList) = l is MyList diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet b/compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet deleted file mode 100644 index 99656c2ab24..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/IsTraits.jet +++ /dev/null @@ -1,4 +0,0 @@ -trait Aaa -trait Bbb - -fun f(a: Aaa) = a is Bbb diff --git a/compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet b/compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet deleted file mode 100644 index f38a4b14fbe..00000000000 --- a/compiler/testData/checkerWithErrorTypes/full/cast/WhenErasedDisallowFromAny.jet +++ /dev/null @@ -1,6 +0,0 @@ -import java.util.List; - -fun ff(l: Any) = when(l) { - is List => 1 - else 2 -} diff --git a/compiler/testData/codegen/patternMatching/is.jet b/compiler/testData/codegen/patternMatching/is.jet index 9fac50c586b..a5b5f33195f 100644 --- a/compiler/testData/codegen/patternMatching/is.jet +++ b/compiler/testData/codegen/patternMatching/is.jet @@ -1,6 +1,6 @@ fun typeName(a: Any?) : String { return when(a) { - is java.util.ArrayList<*> => "array list" + is java.util.ArrayList => "array list" else => "no idea" } } @@ -8,4 +8,4 @@ fun typeName(a: Any?) : String { fun box() : String { if(typeName(java.util.ArrayList ()) != "array list") return "array list failed" return "OK" -} +} \ No newline at end of file