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 8a220250022..e4ffb77ef42 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 @@ -214,6 +214,9 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { if (typeReference == null) return; JetType type = context.expressionTypingServices.getTypeResolver().resolveType(context.scope, typeReference, context.trace, true); checkTypeCompatibility(type, subjectType, typePattern); + if (BasicExpressionTypingVisitor.isCastErased(subjectType, type, JetTypeChecker.INSTANCE)) { + context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(typeReference, type)); + } result.set(Pair.create(context.dataFlowInfo.establishSubtyping(subjectVariables, type), context.dataFlowInfo)); } @@ -334,10 +337,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { if (type == JetStandardClasses.getNullableNothingType() && !subjectType.isNullable()) { context.trace.report(SENSELESS_NULL_IN_WHEN.on(reportErrorOn)); } - - if (BasicExpressionTypingVisitor.isCastErased(subjectType, type, JetTypeChecker.INSTANCE)) { - context.trace.report(Errors.CANNOT_CHECK_FOR_ERASED.on(reportErrorOn, type)); - } } @Override diff --git a/compiler/testData/diagnostics/tests/cast/WhenWithExpression.kt b/compiler/testData/diagnostics/tests/cast/WhenWithExpression.kt new file mode 100644 index 00000000000..0e3d276b23e --- /dev/null +++ b/compiler/testData/diagnostics/tests/cast/WhenWithExpression.kt @@ -0,0 +1,9 @@ +enum class List(val size : Int) { + Nil : List(0) +} + +fun List.join() = + when (this) { + List.Nil -> "[]" // CANNOT_CHECK_FOR_ERASED was reported + else -> "" + } diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index a099b6dbd7c..0fe4e941ee2 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -183,16 +183,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/DelegationNotTotrait.kt"); } - @TestMetadata("Delegation_ScopeInitializationOrder.kt") - public void testDelegation_ScopeInitializationOrder() throws Exception { - doTest("compiler/testData/diagnostics/tests/Delegation_ScopeInitializationOrder.kt"); - } - @TestMetadata("DelegationToJavaIface.kt") public void testDelegationToJavaIface() throws Exception { doTest("compiler/testData/diagnostics/tests/DelegationToJavaIface.kt"); } + @TestMetadata("Delegation_ScopeInitializationOrder.kt") + public void testDelegation_ScopeInitializationOrder() throws Exception { + doTest("compiler/testData/diagnostics/tests/Delegation_ScopeInitializationOrder.kt"); + } + @TestMetadata("DiamondFunction.kt") public void testDiamondFunction() throws Exception { doTest("compiler/testData/diagnostics/tests/DiamondFunction.kt"); @@ -740,6 +740,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/cast/WhenErasedDisallowFromAny.kt"); } + @TestMetadata("WhenWithExpression.kt") + public void testWhenWithExpression() throws Exception { + doTest("compiler/testData/diagnostics/tests/cast/WhenWithExpression.kt"); + } + } @TestMetadata("compiler/testData/diagnostics/tests/checkArguments")