!is is supported

This commit is contained in:
Dmitry Jemerov
2011-05-13 18:21:30 +02:00
parent 26790f1346
commit 82dabdc8d5
3 changed files with 20 additions and 1 deletions
@@ -1310,7 +1310,8 @@ public class ExpressionCodegen extends JetVisitor {
Type type = typeMapper.jvmType((ClassDescriptor) descriptor, OwnerKind.INTERFACE);
v.instanceOf(type);
}
myStack.push(StackValue.onStack(Type.BOOLEAN_TYPE));
StackValue value = StackValue.onStack(Type.BOOLEAN_TYPE);
myStack.push(expression.isNot() ? StackValue.not(value) : value);
}
private void newTypeInfo(JetType jetType) {
@@ -3,6 +3,8 @@ package org.jetbrains.jet.lang.psi;
import com.intellij.lang.ASTNode;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.JetNodeTypes;
import org.jetbrains.jet.lexer.JetTokens;
/**
* @author abreslav
@@ -27,4 +29,13 @@ public class JetIsExpression extends JetExpression {
return findChildByClass(JetPattern.class);
}
@NotNull
public JetSimpleNameExpression getOperationReference() {
return (JetSimpleNameExpression) findChildByType(JetNodeTypes.OPERATION_REFERENCE);
}
public boolean isNot() {
return getOperationReference().getReferencedNameElementType() == JetTokens.NOT_IS;
}
}
@@ -52,6 +52,13 @@ public class TypeInfoTest extends CodegenTestCase {
assertFalse((Boolean) foo.invoke(null));
}
public void testNotIsOperator() throws Exception {
loadText("fun foo(x: Any) = x !is Runnable");
Method foo = generateFunction();
assertTrue((Boolean) foo.invoke(null, new Object()));
assertFalse((Boolean) foo.invoke(null, newRunnable()));
}
private Runnable newRunnable() {
return new Runnable() {
@Override