correctly generate 'in' expressions with IntRange on RHS and a type other than Int on LHS
This commit is contained in:
@@ -2906,7 +2906,8 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return generateElvis(expression);
|
||||
}
|
||||
else if (opToken == JetTokens.IN_KEYWORD || opToken == JetTokens.NOT_IN) {
|
||||
return generateIn(StackValue.expression(Type.INT_TYPE, expression.getLeft(), this), expression.getRight(), reference);
|
||||
return generateIn(StackValue.expression(expressionType(expression.getLeft()), expression.getLeft(), this),
|
||||
expression.getRight(), reference);
|
||||
}
|
||||
else {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCallWithAssert(expression, bindingContext);
|
||||
@@ -2935,7 +2936,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return StackValue.operation(Type.BOOLEAN_TYPE, new Function1<InstructionAdapter, Unit>() {
|
||||
@Override
|
||||
public Unit invoke(InstructionAdapter v) {
|
||||
if (isIntRangeExpr(deparenthesized)) {
|
||||
if (isIntRangeExpr(deparenthesized) && AsmUtil.isIntPrimitive(leftValue.type)) {
|
||||
genInIntRange(leftValue, (JetBinaryExpression) deparenthesized);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
fun IntRange.contains(s: String): Boolean = true
|
||||
|
||||
fun box(): String {
|
||||
return if ("s" in 0..1) "OK" else "fail"
|
||||
}
|
||||
+6
@@ -2130,6 +2130,12 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("rangeContainsString.kt")
|
||||
public void testRangeContainsString() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/ranges/rangeContainsString.kt");
|
||||
doTestWithStdlib(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/boxWithStdlib/ranges/expression")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user