KT-2416 fix contains for ranges with primitive parameters
This commit is contained in:
@@ -1881,9 +1881,18 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
||||
StackValue leftValue = gen(expr);
|
||||
FunctionDescriptor op = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, expression.getOperationReference());
|
||||
assert op != null;
|
||||
leftValue.put(asmType(op.getValueParameters().get(0).getType()), v);
|
||||
genToJVMStack(expression.getRight());
|
||||
v.swap();
|
||||
Type type = asmType(op.getValueParameters().get(0).getType());
|
||||
if(type.getSize() == 1) {
|
||||
leftValue.put(type, v);
|
||||
genToJVMStack(expression.getRight());
|
||||
v.swap();
|
||||
}
|
||||
else {
|
||||
leftValue.put(type, v);
|
||||
genToJVMStack(expression.getRight());
|
||||
v.dupX2();
|
||||
v.pop();
|
||||
}
|
||||
invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v);
|
||||
}
|
||||
return StackValue.onStack(Type.BOOLEAN_TYPE);
|
||||
|
||||
@@ -71,6 +71,20 @@ public class JetTypeMapper {
|
||||
public static final Type ARRAY_GENERIC_TYPE = Type.getType(Object[].class);
|
||||
public static final Type TUPLE0_TYPE = Type.getObjectType("jet/Tuple0");
|
||||
|
||||
public static final Type TYPE_ITERATOR = Type.getObjectType("jet/Iterator");
|
||||
public static final Type TYPE_INT_RANGE = Type.getObjectType("jet/IntRange");
|
||||
public static final Type TYPE_SHARED_VAR = Type.getObjectType("jet/runtime/SharedVar$Object");
|
||||
public static final Type TYPE_SHARED_INT = Type.getObjectType("jet/runtime/SharedVar$Int");
|
||||
public static final Type TYPE_SHARED_DOUBLE = Type.getObjectType("jet/runtime/SharedVar$Double");
|
||||
public static final Type TYPE_SHARED_FLOAT = Type.getObjectType("jet/runtime/SharedVar$Float");
|
||||
public static final Type TYPE_SHARED_BYTE = Type.getObjectType("jet/runtime/SharedVar$Byte");
|
||||
public static final Type TYPE_SHARED_SHORT = Type.getObjectType("jet/runtime/SharedVar$Short");
|
||||
public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/runtime/SharedVar$Char");
|
||||
public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/runtime/SharedVar$Long");
|
||||
public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/runtime/SharedVar$Boolean");
|
||||
public static final Type TYPE_FUNCTION0 = Type.getObjectType("jet/Function0");
|
||||
public static final Type TYPE_FUNCTION1 = Type.getObjectType("jet/Function1");
|
||||
|
||||
private JetStandardLibrary standardLibrary1;
|
||||
public BindingContext bindingContext;
|
||||
private ClosureAnnotator closureAnnotator;
|
||||
@@ -148,20 +162,6 @@ public class JetTypeMapper {
|
||||
private final HashMap<KnownTypeKey, Type> knowTypes = Maps.newHashMap();
|
||||
|
||||
|
||||
public static final Type TYPE_ITERATOR = Type.getObjectType("jet/Iterator");
|
||||
public static final Type TYPE_INT_RANGE = Type.getObjectType("jet/IntRange");
|
||||
public static final Type TYPE_SHARED_VAR = Type.getObjectType("jet/runtime/SharedVar$Object");
|
||||
public static final Type TYPE_SHARED_INT = Type.getObjectType("jet/runtime/SharedVar$Int");
|
||||
public static final Type TYPE_SHARED_DOUBLE = Type.getObjectType("jet/runtime/SharedVar$Double");
|
||||
public static final Type TYPE_SHARED_FLOAT = Type.getObjectType("jet/runtime/SharedVar$Float");
|
||||
public static final Type TYPE_SHARED_BYTE = Type.getObjectType("jet/runtime/SharedVar$Byte");
|
||||
public static final Type TYPE_SHARED_SHORT = Type.getObjectType("jet/runtime/SharedVar$Short");
|
||||
public static final Type TYPE_SHARED_CHAR = Type.getObjectType("jet/runtime/SharedVar$Char");
|
||||
public static final Type TYPE_SHARED_LONG = Type.getObjectType("jet/runtime/SharedVar$Long");
|
||||
public static final Type TYPE_SHARED_BOOLEAN = Type.getObjectType("jet/runtime/SharedVar$Boolean");
|
||||
public static final Type TYPE_FUNCTION0 = Type.getObjectType("jet/Function0");
|
||||
public static final Type TYPE_FUNCTION1 = Type.getObjectType("jet/Function1");
|
||||
|
||||
public static boolean isIntPrimitive(Type type) {
|
||||
return type == Type.INT_TYPE || type == Type.SHORT_TYPE || type == Type.BYTE_TYPE || type == Type.CHAR_TYPE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
fun main(args: Array<String>) {
|
||||
9 in 0..9
|
||||
val intRange = 0..9
|
||||
9 in intRange
|
||||
val charRange = '0'..'9'
|
||||
'9' in charRange
|
||||
val byteRange = 0.toByte()..9.toByte()
|
||||
9.toByte() in byteRange
|
||||
val longRange = 0.toLong()..9.toLong()
|
||||
9.toLong() in longRange
|
||||
val shortRange = 0.toShort()..9.toShort()
|
||||
9.toShort() in shortRange
|
||||
}
|
||||
@@ -366,4 +366,9 @@ public class ControlStructuresTest extends CodegenTestCase {
|
||||
createEnvironmentWithFullJdk();
|
||||
blackBoxFile("regressions/kt2423.kt");
|
||||
}
|
||||
|
||||
public void testKt2416() {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("regressions/kt2416.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ public final class ByteRange implements Range<Byte>, ByteIterable {
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
public boolean contains(byte item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -39,6 +39,13 @@ public final class CharRange implements Range<Character>, CharIterable {
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
public boolean contains(char item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -48,6 +48,13 @@ public final class IntRange implements Range<Integer>, IntIterable {
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
public boolean contains(int item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -46,6 +46,13 @@ public final class LongRange implements Range<Long>, LongIterable {
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
public boolean contains(long item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -46,6 +46,13 @@ public final class ShortRange implements Range<Short>, ShortIterable {
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
public boolean contains(short item) {
|
||||
if (count >= 0) {
|
||||
return item >= start && item < start + count;
|
||||
}
|
||||
return item <= start && item > start + count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
Reference in New Issue
Block a user