From 706bbd7b72e85bfc4d8922599241e7b46952bf15 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Wed, 16 Jul 2014 20:56:28 +0400 Subject: [PATCH] When2Switch: check if entry set is not empty --- .../jetbrains/jet/codegen/when/SwitchCodegenUtil.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/when/SwitchCodegenUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/when/SwitchCodegenUtil.java index a45f446542c..74730d893ab 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/when/SwitchCodegenUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/when/SwitchCodegenUtil.java @@ -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 entries = expression.getEntries(); + return !entries.isEmpty() && (entries.size() > 1 || !entries.get(0).isElse()); + } + private static boolean isIntegralConstantsSwitch( @NotNull JetWhenExpression expression, @NotNull Type subjectType,