From f40cf97279511554bf843a48ff9f8fb36f441124 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sun, 25 Dec 2011 15:55:57 +0200 Subject: [PATCH] fix for KT-870 - when without parameter --- .../jet/codegen/ExpressionCodegen.java | 30 ++++++++++++------- .../testData/codegen/regressions/kt870.jet | 5 ++++ .../jet/codegen/ControlStructuresTest.java | 5 ++++ 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 compiler/testData/codegen/regressions/kt870.jet diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 8dafa6b2690..59cf9453497 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -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); } else if (pattern instanceof JetExpressionPattern) { - final Type subjectType = expressionToMatch.type; - expressionToMatch.dupReceiver(v); - expressionToMatch.put(subjectType, v); - JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression(); - Type condType = isNumberPrimitive(subjectType) ? expressionType(condExpression) : TYPE_OBJECT; - gen(condExpression, condType); - return generateEqualsForExpressionsOnStack(JetTokens.EQEQ, subjectType, condType, false, false); + if(expressionToMatch != null) { + final Type subjectType = expressionToMatch.type; + expressionToMatch.dupReceiver(v); + expressionToMatch.put(subjectType, v); + JetExpression condExpression = ((JetExpressionPattern) pattern).getExpression(); + Type condType = isNumberPrimitive(subjectType) ? expressionType(condExpression) : TYPE_OBJECT; + 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) { 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(); final Type subjectType = expressionType(expr); final Type resultType = expressionType(expression); - final int subjectLocal = myFrameMap.enterTemp(subjectType.getSize()); - gen(expr, subjectType); - v.store(subjectLocal, subjectType); + final int subjectLocal = expr != null ? myFrameMap.enterTemp(subjectType.getSize()) : -1; + if(subjectLocal != -1) { + gen(expr, subjectType); + v.store(subjectLocal, subjectType); + } Label end = new Label(); 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; JetPattern pattern = patternCondition.getPattern(); conditionValue = generatePatternMatch(pattern, patternCondition.isNegated(), - StackValue.local(subjectLocal, subjectType), nextEntry); + subjectLocal == -1 ? null : StackValue.local(subjectLocal, subjectType), nextEntry); } else { throw new UnsupportedOperationException("unsupported kind of when condition"); diff --git a/compiler/testData/codegen/regressions/kt870.jet b/compiler/testData/codegen/regressions/kt870.jet new file mode 100644 index 00000000000..9f83928b716 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt870.jet @@ -0,0 +1,5 @@ +fun box() = when { + 1 > 2 -> "false" + 1 >= 1 -> "OK" + else -> "else" + } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index 2869aa145b4..36e3fe909f0 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -236,6 +236,11 @@ public class ControlStructuresTest extends CodegenTestCase { // System.out.println(generateToText()); } + public void testKt870() throws Exception { + blackBoxFile("regressions/kt870.jet"); +// System.out.println(generateToText()); + } + public void testQuicksort() throws Exception { blackBoxFile("controlStructures/quicksort.jet"); // System.out.println(generateToText());