diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java index 5356ae2e235..5b147979ee4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java @@ -17,9 +17,11 @@ package org.jetbrains.jet.lang.cfg; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.descriptors.ClassDescriptor; import org.jetbrains.jet.lang.descriptors.ClassKind; import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingTrace; @@ -65,15 +67,22 @@ public class WhenChecker { return isExhaust && notEmpty; } - private static boolean containsEnumEntryCase(@NotNull JetWhenExpression whenExpression, @NotNull ClassDescriptor enumEntry, @NotNull BindingTrace trace) { + private static boolean containsEnumEntryCase( + @NotNull JetWhenExpression whenExpression, + @NotNull ClassDescriptor enumEntry, + @NotNull BindingTrace trace + ) { assert enumEntry.getKind() == ClassKind.ENUM_ENTRY; for (JetWhenEntry whenEntry : whenExpression.getEntries()) { for (JetWhenCondition condition : whenEntry.getConditions()) { if (condition instanceof JetWhenConditionWithExpression) { JetExpression patternExpression = ((JetWhenConditionWithExpression) condition).getExpression(); - JetType type = trace.get(BindingContext.EXPRESSION_TYPE, patternExpression); - if (type == null) continue; - if (type.getConstructor().getDeclarationDescriptor() == enumEntry) { + JetSimpleNameExpression reference = getReference(patternExpression); + if (reference == null) continue; + DeclarationDescriptor target = trace.get(BindingContext.REFERENCE_TARGET, reference); + if (target == null) continue; + ClassDescriptor classDescriptor = trace.get(BindingContext.OBJECT_DECLARATION_CLASS, (VariableDescriptor) target); + if (classDescriptor == enumEntry) { return true; } } @@ -81,4 +90,18 @@ public class WhenChecker { } return false; } + + @Nullable + private static JetSimpleNameExpression getReference(@Nullable JetExpression expression) { + if (expression == null) { + return null; + } + if (expression instanceof JetSimpleNameExpression) { + return (JetSimpleNameExpression) expression; + } + if (expression instanceof JetQualifiedExpression) { + return getReference(((JetQualifiedExpression) expression).getSelectorExpression()); + } + return null; + } }