Fix for EA-68871 #EA-68871 Fixed
This commit is contained in:
@@ -47,7 +47,7 @@ public class SwitchCodegenUtil {
|
|||||||
// ensure that expression is constant
|
// ensure that expression is constant
|
||||||
JetExpression patternExpression = ((JetWhenConditionWithExpression) condition).getExpression();
|
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);
|
CompileTimeConstant constant = ExpressionCodegen.getCompileTimeConstant(patternExpression, bindingContext);
|
||||||
if (constant == null || !predicate.invoke(constant)) {
|
if (constant == null || !predicate.invoke(constant)) {
|
||||||
|
|||||||
@@ -149,9 +149,12 @@ public final class WhenChecker {
|
|||||||
for (JetWhenEntry entry : expression.getEntries()) {
|
for (JetWhenEntry entry : expression.getEntries()) {
|
||||||
for (JetWhenCondition condition : entry.getConditions()) {
|
for (JetWhenCondition condition : entry.getConditions()) {
|
||||||
if (condition instanceof JetWhenConditionWithExpression) {
|
if (condition instanceof JetWhenConditionWithExpression) {
|
||||||
JetType type = trace.getBindingContext().getType(((JetWhenConditionWithExpression) condition).getExpression());
|
JetWhenConditionWithExpression conditionWithExpression = (JetWhenConditionWithExpression) condition;
|
||||||
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
|
if (conditionWithExpression.getExpression() != null) {
|
||||||
return true;
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
+37
@@ -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);
|
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")
|
@TestMetadata("ExhaustiveBoolean.kt")
|
||||||
public void testExhaustiveBoolean() throws Exception {
|
public void testExhaustiveBoolean() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/when/ExhaustiveBoolean.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user