fix for KT-80
This commit is contained in:
@@ -809,7 +809,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : isInterface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, owner, functionDescriptor.getName(), typeMapper.mapSignature(functionDescriptor.getName(),functionDescriptor).getDescriptor());
|
v.visitMethodInsn(isStatic ? Opcodes.INVOKESTATIC : isInterface ? Opcodes.INVOKEINTERFACE : Opcodes.INVOKEVIRTUAL, owner, functionDescriptor.getName(), typeMapper.mapSignature(functionDescriptor.getName(),functionDescriptor).getDescriptor());
|
||||||
StackValue.onStack(typeMapper.mapType(functionDescriptor.getReturnType())).coerce(type, v);
|
StackValue.onStack(typeMapper.mapType(functionDescriptor.getReturnType())).coerce(type, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StackValue intermediateValueForProperty(PropertyDescriptor propertyDescriptor, final boolean forceField, boolean forceInterface) {
|
public StackValue intermediateValueForProperty(PropertyDescriptor propertyDescriptor, final boolean forceField, boolean forceInterface) {
|
||||||
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
DeclarationDescriptor containingDeclaration = propertyDescriptor.getContainingDeclaration();
|
||||||
boolean isStatic = containingDeclaration instanceof NamespaceDescriptorImpl;
|
boolean isStatic = containingDeclaration instanceof NamespaceDescriptorImpl;
|
||||||
@@ -1990,11 +1990,42 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
@Nullable Label nextEntry) {
|
@Nullable Label nextEntry) {
|
||||||
StackValue conditionValue;
|
StackValue conditionValue;
|
||||||
if (condition instanceof JetWhenConditionInRange) {
|
if (condition instanceof JetWhenConditionInRange) {
|
||||||
JetExpression range = ((JetWhenConditionInRange) condition).getRangeExpression();
|
JetWhenConditionInRange conditionInRange = (JetWhenConditionInRange) condition;
|
||||||
gen(range, RANGE_TYPE);
|
JetExpression rangeExpression = conditionInRange.getRangeExpression();
|
||||||
new StackValue.Local(subjectLocal, subjectType).put(INTEGER_TYPE, v);
|
if(isIntRangeExpr(rangeExpression)) {
|
||||||
v.invokeinterface(CLASS_RANGE, "contains", "(Ljava/lang/Comparable;)Z");
|
v.iconst(1);
|
||||||
conditionValue = new StackValue.OnStack(Type.BOOLEAN_TYPE);
|
//noinspection ConstantConditions
|
||||||
|
new StackValue.Local(subjectLocal, subjectType).put(Type.INT_TYPE, v);
|
||||||
|
JetBinaryExpression binaryExpression = (JetBinaryExpression) rangeExpression;
|
||||||
|
gen(binaryExpression.getLeft(), Type.INT_TYPE);
|
||||||
|
Label lok = new Label();
|
||||||
|
v.ificmpge(lok);
|
||||||
|
v.pop();
|
||||||
|
v.iconst(0);
|
||||||
|
v.mark(lok);
|
||||||
|
|
||||||
|
v.iconst(1);
|
||||||
|
new StackValue.Local(subjectLocal, subjectType).put(Type.INT_TYPE, v);
|
||||||
|
gen(binaryExpression.getRight(), Type.INT_TYPE);
|
||||||
|
Label rok = new Label();
|
||||||
|
v.ificmple(rok);
|
||||||
|
v.pop();
|
||||||
|
v.iconst(0);
|
||||||
|
v.mark(rok);
|
||||||
|
|
||||||
|
v.and(Type.INT_TYPE);
|
||||||
|
if(conditionInRange.getOperationReference().getReferencedNameElementType() == JetTokens.NOT_IN) {
|
||||||
|
v.iconst(1);
|
||||||
|
v.xor(Type.INT_TYPE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
FunctionDescriptor op = (FunctionDescriptor) bindingContext.get(BindingContext.REFERENCE_TARGET, conditionInRange.getOperationReference());
|
||||||
|
genToJVMStack(rangeExpression);
|
||||||
|
new StackValue.Local(subjectLocal, subjectType).put(JetTypeMapper.TYPE_OBJECT, v);
|
||||||
|
invokeFunctionNoParams(op, Type.BOOLEAN_TYPE, v);
|
||||||
|
}
|
||||||
|
return StackValue.onStack(Type.BOOLEAN_TYPE);
|
||||||
}
|
}
|
||||||
else if (condition instanceof JetWhenConditionIsPattern) {
|
else if (condition instanceof JetWhenConditionIsPattern) {
|
||||||
JetWhenConditionIsPattern patternCondition = (JetWhenConditionIsPattern) condition;
|
JetWhenConditionIsPattern patternCondition = (JetWhenConditionIsPattern) condition;
|
||||||
@@ -2032,6 +2063,20 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
return conditionValue;
|
return conditionValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isIntRangeExpr(JetExpression rangeExpression) {
|
||||||
|
if(rangeExpression instanceof JetBinaryExpression) {
|
||||||
|
JetBinaryExpression binaryExpression = (JetBinaryExpression) rangeExpression;
|
||||||
|
if (binaryExpression.getOperationReference().getReferencedNameElementType() == JetTokens.RANGE) {
|
||||||
|
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, rangeExpression);
|
||||||
|
final DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||||
|
if (isClass(descriptor, "IntRange")) { // TODO IntRange subclasses
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false ;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitTupleExpression(JetTupleExpression expression, StackValue receiver) {
|
public StackValue visitTupleExpression(JetTupleExpression expression, StackValue receiver) {
|
||||||
final List<JetExpression> entries = expression.getEntries();
|
final List<JetExpression> entries = expression.getEntries();
|
||||||
|
|||||||
@@ -275,7 +275,19 @@ public abstract class StackValue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void put(Type type, InstructionAdapter v) {
|
public void put(Type type, InstructionAdapter v) {
|
||||||
v.aconst(value);
|
if(value instanceof Integer)
|
||||||
|
v.iconst((Integer) value);
|
||||||
|
else
|
||||||
|
if(value instanceof Long)
|
||||||
|
v.lconst((Long) value);
|
||||||
|
else
|
||||||
|
if(value instanceof Float)
|
||||||
|
v.fconst((Float) value);
|
||||||
|
else
|
||||||
|
if(value instanceof Double)
|
||||||
|
v.dconst((Double) value);
|
||||||
|
else
|
||||||
|
v.aconst(value);
|
||||||
coerce(type, v);
|
coerce(type, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
fun isDigit(a: Int) = when(a) {
|
fun isDigit(a: Int) : String {
|
||||||
in 0..9 => "digit"
|
val aa = java.util.ArrayList<Int> ()
|
||||||
else => "something"
|
aa.add(239)
|
||||||
|
|
||||||
|
return when(a) {
|
||||||
|
in aa => "array list"
|
||||||
|
in 0..9 => "digit"
|
||||||
|
!in 0..100 => "not small"
|
||||||
|
else => "something"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,8 +39,12 @@ public class PatternMatchingTest extends CodegenTestCase {
|
|||||||
loadFile();
|
loadFile();
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
Method foo = generateFunction();
|
Method foo = generateFunction();
|
||||||
|
assertEquals("array list", foo.invoke(null, 239));
|
||||||
|
assertEquals("digit", foo.invoke(null, 0));
|
||||||
assertEquals("digit", foo.invoke(null, 9));
|
assertEquals("digit", foo.invoke(null, 9));
|
||||||
|
assertEquals("digit", foo.invoke(null, 5));
|
||||||
assertEquals("something", foo.invoke(null, 19));
|
assertEquals("something", foo.invoke(null, 19));
|
||||||
|
assertEquals("not small", foo.invoke(null, 190));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRangeChar() throws Exception {
|
public void testRangeChar() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user