Fix for EA-68871 #EA-68871 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-05-28 14:35:54 +03:00
parent bd17db6f3e
commit 969993bd09
7 changed files with 76 additions and 4 deletions
@@ -47,7 +47,7 @@ public class SwitchCodegenUtil {
// ensure that expression is constant
JetExpression patternExpression = ((JetWhenConditionWithExpression) condition).getExpression();
assert patternExpression != null : "expression in when should not be null";
if (patternExpression == null) return false;
CompileTimeConstant constant = ExpressionCodegen.getCompileTimeConstant(patternExpression, bindingContext);
if (constant == null || !predicate.invoke(constant)) {
@@ -149,9 +149,12 @@ public final class WhenChecker {
for (JetWhenEntry entry : expression.getEntries()) {
for (JetWhenCondition condition : entry.getConditions()) {
if (condition instanceof JetWhenConditionWithExpression) {
JetType type = trace.getBindingContext().getType(((JetWhenConditionWithExpression) condition).getExpression());
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
return true;
JetWhenConditionWithExpression conditionWithExpression = (JetWhenConditionWithExpression) condition;
if (conditionWithExpression.getExpression() != null) {
JetType type = trace.getBindingContext().getType(conditionWithExpression.getExpression());
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
return true;
}
}
}
}
@@ -0,0 +1,8 @@
// EA-68871: empty when condition
fun foo(arg: Int): Int {
when (arg) {
0 -> return 0
<!SYNTAX!><!>-> return 4
else -> return -1
}
}
@@ -0,0 +1,3 @@
package
internal fun foo(/*0*/ arg: kotlin.Int): kotlin.Int
@@ -0,0 +1,9 @@
// EA-68871: empty when condition
enum class My { FIRST, SECOND }
fun foo(arg: My): Int {
when (arg) {
My.FIRST -> return 0
<!SYNTAX!><!>-> return 4
else -> return -1
}
}
@@ -0,0 +1,37 @@
package
internal fun foo(/*0*/ arg: My): kotlin.Int
internal final enum class My : kotlin.Enum<My> {
public enum entry FIRST : My {
private constructor FIRST()
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final override /*1*/ /*fake_override*/ fun name(): kotlin.String
public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public enum entry SECOND : My {
private constructor SECOND()
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final override /*1*/ /*fake_override*/ fun name(): kotlin.String
public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
private constructor My()
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: My): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final override /*1*/ /*fake_override*/ fun name(): kotlin.String
public final override /*1*/ /*fake_override*/ fun ordinal(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): My
public final /*synthesized*/ fun values(): kotlin.Array<My>
}
@@ -13584,6 +13584,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("EmptyConditionWithExpression.kt")
public void testEmptyConditionWithExpression() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/EmptyConditionWithExpression.kt");
doTest(fileName);
}
@TestMetadata("EmptyConditionWithExpressionEnum.kt")
public void testEmptyConditionWithExpressionEnum() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/EmptyConditionWithExpressionEnum.kt");
doTest(fileName);
}
@TestMetadata("ExhaustiveBoolean.kt")
public void testExhaustiveBoolean() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.kt");