KT-613 verify error ++/-- in presence of this|receiver

This commit is contained in:
Alex Tkachman
2011-11-25 10:32:17 +02:00
parent b990792917
commit 21a0d1f85c
3 changed files with 28 additions and 3 deletions
@@ -5,6 +5,7 @@ import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.JetTypeMapper;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.InstructionAdapter;
@@ -23,7 +24,10 @@ public class Increment implements IntrinsicMethod {
@Override
public StackValue generate(ExpressionCodegen codegen, InstructionAdapter v, Type expectedType, PsiElement element, List<JetExpression> arguments, StackValue receiver) {
final JetExpression operand = arguments.get(0);
JetExpression operand = arguments.get(0);
while(operand instanceof JetParenthesizedExpression) {
operand = ((JetParenthesizedExpression)operand).getExpression();
}
if (operand instanceof JetReferenceExpression) {
final int index = codegen.indexOfLocal((JetReferenceExpression) operand);
if (index >= 0 && JetTypeMapper.isIntPrimitive(expectedType)) {
@@ -33,6 +37,7 @@ public class Increment implements IntrinsicMethod {
}
StackValue value = codegen.genQualified(receiver, operand);
value. dupReceiver(v);
value. dupReceiver(v);
value.put(expectedType, v);
if (expectedType == Type.LONG_TYPE) {
v.lconst(myDelta);
@@ -44,10 +49,11 @@ public class Increment implements IntrinsicMethod {
v.dconst(myDelta);
}
else {
v.aconst(myDelta);
v.iconst(myDelta);
}
v.add(expectedType);
value.store(v);
return value;
value.put(expectedType, v);
return StackValue.onStack(expectedType);
}
}
@@ -0,0 +1,15 @@
namespace name
class Test() {
var i = 5
val ten = 10.lng
fun Long.t() = this.int + i++ + ++i
fun tt() = ten.t()
}
fun box() : String {
var m = Test()
return if((m.i)++ == 5 && ++(m.i) == 7 && m.tt() == 26) "OK" else "fail"
}
@@ -136,6 +136,10 @@ public class PropertyGenTest extends CodegenTestCase {
blackBoxFile("regressions/kt257.jet");
}
public void testKt613 () throws Exception {
blackBoxFile("regressions/kt613.jet");
}
public void testKt160() throws Exception {
loadText("internal val s = java.lang.Double.toString(1.0)");
final Method method = generateFunction("getS");