When2Switch: check if entry set is not empty

This commit is contained in:
Denis Zharkov
2014-07-16 20:56:28 +04:00
committed by Evgeny Gerashchenko
parent d4cb822ee8
commit 706bbd7b72
@@ -101,6 +101,10 @@ public class SwitchCodegenUtil {
boolean isStatement,
@NotNull ExpressionCodegen codegen
) {
if (!isThereEntriesButElse(expression)) {
return null;
}
Type subjectType = codegen.expressionType(expression.getSubjectExpression());
BindingContext bindingContext = codegen.getBindingContext();
@@ -121,6 +125,11 @@ public class SwitchCodegenUtil {
return null;
}
private static boolean isThereEntriesButElse(@NotNull JetWhenExpression expression) {
List<JetWhenEntry> entries = expression.getEntries();
return !entries.isEmpty() && (entries.size() > 1 || !entries.get(0).isElse());
}
private static boolean isIntegralConstantsSwitch(
@NotNull JetWhenExpression expression,
@NotNull Type subjectType,