generate 'as'

This commit is contained in:
Dmitry Jemerov
2011-05-30 15:40:13 +04:00
parent 5c9a807c57
commit d4f0486139
3 changed files with 37 additions and 19 deletions
@@ -1,6 +1,7 @@
package org.jetbrains.jet.codegen;
import jet.JetObject;
import jet.TypeCastException;
import jet.typeinfo.TypeInfo;
import java.lang.reflect.Method;
@@ -31,13 +32,20 @@ public class TypeInfoTest extends CodegenTestCase {
public void testAsSafeOperator() throws Exception {
loadText("fun foo(x: Any) = x as? Runnable");
System.out.println(generateToText());
Method foo = generateFunction();
assertNull(foo.invoke(null, new Object()));
Runnable r = newRunnable();
assertSame(r, foo.invoke(null, r));
}
public void testAsOperator() throws Exception {
loadText("fun foo(x: Any) = x as Runnable");
Method foo = generateFunction();
Runnable r = newRunnable();
assertSame(r, foo.invoke(null, r));
assertThrows(foo, TypeCastException.class, null, new Object());
}
public void testIsOperator() throws Exception {
loadText("fun foo(x: Any) = x is Runnable");
Method foo = generateFunction();