fix for KT-870 - when without parameter
This commit is contained in:
@@ -2410,13 +2410,19 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
return generateTuplePatternMatch((JetTuplePattern) pattern, negated, expressionToMatch, nextEntry);
|
return generateTuplePatternMatch((JetTuplePattern) pattern, negated, expressionToMatch, nextEntry);
|
||||||
}
|
}
|
||||||
else if (pattern instanceof JetExpressionPattern) {
|
else if (pattern instanceof JetExpressionPattern) {
|
||||||
final Type subjectType = expressionToMatch.type;
|
if(expressionToMatch != null) {
|
||||||
expressionToMatch.dupReceiver(v);
|
final Type subjectType = expressionToMatch.type;
|
||||||
expressionToMatch.put(subjectType, v);
|
expressionToMatch.dupReceiver(v);
|
||||||
JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression();
|
expressionToMatch.put(subjectType, v);
|
||||||
Type condType = isNumberPrimitive(subjectType) ? expressionType(condExpression) : TYPE_OBJECT;
|
JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression();
|
||||||
gen(condExpression, condType);
|
Type condType = isNumberPrimitive(subjectType) ? expressionType(condExpression) : TYPE_OBJECT;
|
||||||
return generateEqualsForExpressionsOnStack(JetTokens.EQEQ, subjectType, condType, false, false);
|
gen(condExpression, condType);
|
||||||
|
return generateEqualsForExpressionsOnStack(JetTokens.EQEQ, subjectType, condType, false, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression();
|
||||||
|
return gen(condExpression);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (pattern instanceof JetWildcardPattern) {
|
else if (pattern instanceof JetWildcardPattern) {
|
||||||
return StackValue.constant(!negated, Type.BOOLEAN_TYPE);
|
return StackValue.constant(!negated, Type.BOOLEAN_TYPE);
|
||||||
@@ -2665,9 +2671,11 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
JetExpression expr = expression.getSubjectExpression();
|
JetExpression expr = expression.getSubjectExpression();
|
||||||
final Type subjectType = expressionType(expr);
|
final Type subjectType = expressionType(expr);
|
||||||
final Type resultType = expressionType(expression);
|
final Type resultType = expressionType(expression);
|
||||||
final int subjectLocal = myFrameMap.enterTemp(subjectType.getSize());
|
final int subjectLocal = expr != null ? myFrameMap.enterTemp(subjectType.getSize()) : -1;
|
||||||
gen(expr, subjectType);
|
if(subjectLocal != -1) {
|
||||||
v.store(subjectLocal, subjectType);
|
gen(expr, subjectType);
|
||||||
|
v.store(subjectLocal, subjectType);
|
||||||
|
}
|
||||||
|
|
||||||
Label end = new Label();
|
Label end = new Label();
|
||||||
boolean hasElse = false;
|
boolean hasElse = false;
|
||||||
@@ -2736,7 +2744,7 @@ If finally block is present, its last expression is the value of try expression.
|
|||||||
JetWhenConditionIsPattern patternCondition = (JetWhenConditionIsPattern) condition;
|
JetWhenConditionIsPattern patternCondition = (JetWhenConditionIsPattern) condition;
|
||||||
JetPattern pattern = patternCondition.getPattern();
|
JetPattern pattern = patternCondition.getPattern();
|
||||||
conditionValue = generatePatternMatch(pattern, patternCondition.isNegated(),
|
conditionValue = generatePatternMatch(pattern, patternCondition.isNegated(),
|
||||||
StackValue.local(subjectLocal, subjectType), nextEntry);
|
subjectLocal == -1 ? null : StackValue.local(subjectLocal, subjectType), nextEntry);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException("unsupported kind of when condition");
|
throw new UnsupportedOperationException("unsupported kind of when condition");
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun box() = when {
|
||||||
|
1 > 2 -> "false"
|
||||||
|
1 >= 1 -> "OK"
|
||||||
|
else -> "else"
|
||||||
|
}
|
||||||
@@ -236,6 +236,11 @@ public class ControlStructuresTest extends CodegenTestCase {
|
|||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testKt870() throws Exception {
|
||||||
|
blackBoxFile("regressions/kt870.jet");
|
||||||
|
// System.out.println(generateToText());
|
||||||
|
}
|
||||||
|
|
||||||
public void testQuicksort() throws Exception {
|
public void testQuicksort() throws Exception {
|
||||||
blackBoxFile("controlStructures/quicksort.jet");
|
blackBoxFile("controlStructures/quicksort.jet");
|
||||||
// System.out.println(generateToText());
|
// System.out.println(generateToText());
|
||||||
|
|||||||
Reference in New Issue
Block a user