From 58666f3eb79378bc779decd1a8034ca836f71910 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Sat, 2 Jun 2012 23:17:42 +0200 Subject: [PATCH] unwrap parentheses around range expressions in pattern matching conditions (KT-1742) (thanks to Sergey Mashkov for the suggested fix) --- .../src/org/jetbrains/jet/codegen/ExpressionCodegen.java | 3 +++ compiler/testData/codegen/regressions/kt1742.kt | 7 +++++++ .../org/jetbrains/jet/codegen/ControlStructuresTest.java | 5 +++++ 3 files changed, 15 insertions(+) create mode 100644 compiler/testData/codegen/regressions/kt1742.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index ffcb441b723..97d5ac35b78 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2868,6 +2868,9 @@ If finally block is present, its last expression is the value of try expression. if (condition instanceof JetWhenConditionInRange) { JetWhenConditionInRange conditionInRange = (JetWhenConditionInRange) condition; JetExpression rangeExpression = conditionInRange.getRangeExpression(); + while (rangeExpression instanceof JetParenthesizedExpression) { + rangeExpression = ((JetParenthesizedExpression)rangeExpression).getExpression(); + } if(isIntRangeExpr(rangeExpression)) { getInIntRange(new StackValue.Local(subjectLocal, subjectType), (JetBinaryExpression) rangeExpression, conditionInRange.getOperationReference().getReferencedNameElementType() == JetTokens.NOT_IN); } diff --git a/compiler/testData/codegen/regressions/kt1742.kt b/compiler/testData/codegen/regressions/kt1742.kt new file mode 100644 index 00000000000..6e950e30e41 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1742.kt @@ -0,0 +1,7 @@ +fun box(): String { + val x = 2 + return when(x) { + in (1..3) -> "OK" + else -> "fail" + } +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java index adc46e485c9..b28ed3f9ba5 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ControlStructuresTest.java @@ -341,4 +341,9 @@ public class ControlStructuresTest extends CodegenTestCase { createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS); blackBoxFile("regressions/kt1899.kt"); } + + public void testKt1742() throws Exception { + createEnvironmentWithMockJdkAndIdeaAnnotations(CompilerSpecialMode.JDK_HEADERS); + blackBoxFile("regressions/kt1742.kt"); + } }