generate no-arg typeinfo
This commit is contained in:
@@ -829,11 +829,18 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
if (args.size() == 1) {
|
||||
gen(args.get(0).getArgumentExpression(), JET_OBJECT_TYPE);
|
||||
v.invokeinterface("jet/JetObject", "getTypeInfo", "()Ljet/typeinfo/TypeInfo;");
|
||||
myStack.push(StackValue.onStack(JetTypeMapper.TYPE_TYPEINFO));
|
||||
}
|
||||
else if (args.size() == 0) {
|
||||
final List<JetTypeProjection> typeArguments = expression.getTypeArguments();
|
||||
if (typeArguments.size() != 1) {
|
||||
throw new UnsupportedOperationException("one type argument expected");
|
||||
}
|
||||
pushTypeArgument(typeArguments.get(0));
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException("only one-arg form of typeinfo() is now supported");
|
||||
throw new UnsupportedOperationException("no such form of typeinfo()");
|
||||
}
|
||||
myStack.push(StackValue.onStack(JetTypeMapper.TYPE_TYPEINFO));
|
||||
}
|
||||
|
||||
private PsiElement resolveCalleeToDeclaration(DeclarationDescriptor funDescriptor) {
|
||||
@@ -1503,11 +1510,15 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
|
||||
private void pushTypeArguments(JetCall expression) {
|
||||
for (JetTypeProjection jetTypeArgument : expression.getTypeArguments()) {
|
||||
JetType typeArgument = bindingContext.resolveTypeReference(jetTypeArgument.getTypeReference());
|
||||
generateTypeInfo(typeArgument);
|
||||
pushTypeArgument(jetTypeArgument);
|
||||
}
|
||||
}
|
||||
|
||||
private void pushTypeArgument(JetTypeProjection jetTypeArgument) {
|
||||
JetType typeArgument = bindingContext.resolveTypeReference(jetTypeArgument.getTypeReference());
|
||||
generateTypeInfo(typeArgument);
|
||||
}
|
||||
|
||||
private void pushOuterClassArguments(ClassDescriptor classDecl) {
|
||||
if (classDecl.getContainingDeclaration() instanceof ClassDescriptor) {
|
||||
v.load(0, JetTypeMapper.jetImplementationType(classDecl));
|
||||
|
||||
@@ -23,13 +23,20 @@ public class TypeInfoTest extends CodegenTestCase {
|
||||
assertNotNull(typeInfo);
|
||||
}
|
||||
|
||||
public void testTypeOfOperator() throws Exception {
|
||||
public void testOneArgTypeinfo() throws Exception {
|
||||
loadFile();
|
||||
Method foo = generateFunction();
|
||||
TypeInfo typeInfo = (TypeInfo) foo.invoke(null);
|
||||
assertNotNull(typeInfo);
|
||||
}
|
||||
|
||||
public void testNoArgTypeinfo() throws Exception {
|
||||
loadText("fun foo() = typeinfo.typeinfo<Int>()");
|
||||
Method foo = generateFunction();
|
||||
TypeInfo typeInfo = (TypeInfo) foo.invoke(null);
|
||||
assertSame(TypeInfo.INT_TYPE_INFO, typeInfo);
|
||||
}
|
||||
|
||||
public void testAsSafeOperator() throws Exception {
|
||||
loadText("fun foo(x: Any) = x as? Runnable");
|
||||
Method foo = generateFunction();
|
||||
|
||||
Reference in New Issue
Block a user