KT-2457 Verify error when comparing not null value with null in when
backend-side changes
This commit is contained in:
@@ -2848,7 +2848,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
}
|
}
|
||||||
else if (pattern instanceof JetExpressionPattern) {
|
else if (pattern instanceof JetExpressionPattern) {
|
||||||
if (expressionToMatch != null) {
|
if (expressionToMatch != null) {
|
||||||
final Type subjectType = expressionToMatch.type;
|
Type subjectType = expressionToMatch.type;
|
||||||
expressionToMatch.dupReceiver(v);
|
expressionToMatch.dupReceiver(v);
|
||||||
expressionToMatch.put(subjectType, v);
|
expressionToMatch.put(subjectType, v);
|
||||||
JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression();
|
JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression();
|
||||||
@@ -2857,6 +2857,10 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
Type condType;
|
Type condType;
|
||||||
if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) {
|
if (isNumberPrimitive(subjectType) || subjectType.getSort() == Type.BOOLEAN) {
|
||||||
condType = asmType(condJetType);
|
condType = asmType(condJetType);
|
||||||
|
if (!(isNumberPrimitive(condType) || condType.getSort() == Type.BOOLEAN)) {
|
||||||
|
subjectType = JetTypeMapper.boxType(subjectType);
|
||||||
|
expressionToMatch.coerce(subjectType, v);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
condType = TYPE_OBJECT;
|
condType = TYPE_OBJECT;
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo(i: Int, j: Int?): String =
|
||||||
|
when (i) {
|
||||||
|
j -> "OK"
|
||||||
|
else -> "Fail"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String = foo(0, 0)
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fun foo(i: Int) : Int =
|
||||||
|
when (i) {
|
||||||
|
1 -> 1
|
||||||
|
null -> 1
|
||||||
|
else -> 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String = if (foo(1) == 1) "OK" else "fail"
|
||||||
@@ -162,4 +162,12 @@ public class PatternMatchingTest extends CodegenTestCase {
|
|||||||
public void testKt2466() throws Exception {
|
public void testKt2466() throws Exception {
|
||||||
blackBoxFile("patternMatching/kt2466.kt");
|
blackBoxFile("patternMatching/kt2466.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMatchNotNullAgainstNullable() throws Exception {
|
||||||
|
blackBoxFile("patternMatching/matchNotNullAgainstNullable.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testKt2457() throws Exception {
|
||||||
|
blackBoxFile("regressions/kt2457.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user