failing test for unary minus
This commit is contained in:
@@ -581,6 +581,23 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPrefixExpression(JetPrefixExpression expression) {
|
||||
DeclarationDescriptor op = bindingContext.resolveReferenceExpression(expression.getOperationSign());
|
||||
if (op instanceof FunctionDescriptor) {
|
||||
JetType returnType = bindingContext.getExpressionType(expression);
|
||||
final Type asmType = typeMapper.mapType(returnType);
|
||||
DeclarationDescriptor cls = op.getContainingDeclaration();
|
||||
if (isNumberPrimitive(cls) && op.getName().equals("minus")) {
|
||||
gen(expression.getBaseExpression(), asmType);
|
||||
v.neg(asmType);
|
||||
myStack.push(StackValue.onStack(asmType));
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new UnsupportedOperationException("Don't know how to generate this prefix expression");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitProperty(JetProperty property) {
|
||||
PropertyDescriptor propertyDescriptor = bindingContext.getPropertyDescriptor(property);
|
||||
|
||||
@@ -336,6 +336,12 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
||||
assertTrue(delta <= 1.0);
|
||||
}
|
||||
|
||||
public void testNeg() throws Exception {
|
||||
loadText("fun foo(a: Int): Int = -a");
|
||||
final Method main = generateFunction();
|
||||
assertEquals(-10, main.invoke(null, 10));
|
||||
}
|
||||
|
||||
private void binOpTest(final String text, final Object arg1, final Object arg2, final Object expected) throws Exception {
|
||||
loadText(text);
|
||||
System.out.println(generateToText());
|
||||
|
||||
Reference in New Issue
Block a user