'is' works on class type parameters
This commit is contained in:
@@ -1688,10 +1688,7 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
|
||||
private void generateInstanceOf(Runnable expressionGen, JetType jetType, boolean leaveExpressionOnStack) {
|
||||
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (!(descriptor instanceof ClassDescriptor)) {
|
||||
throw new UnsupportedOperationException("don't know how to handle non-class types");
|
||||
}
|
||||
if (jetType.getArguments().size() > 0) {
|
||||
if (jetType.getArguments().size() > 0 || !(descriptor instanceof ClassDescriptor)) {
|
||||
generateTypeInfo(jetType);
|
||||
expressionGen.run();
|
||||
if (leaveExpressionOnStack) {
|
||||
@@ -1712,14 +1709,8 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
private void generateTypeInfo(JetType jetType) {
|
||||
DeclarationDescriptor declarationDescriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (declarationDescriptor instanceof TypeParameterDescriptor) {
|
||||
DeclarationDescriptor containingDeclaration = declarationDescriptor.getContainingDeclaration();
|
||||
if (containingDeclaration == contextType && contextType instanceof ClassDescriptor) {
|
||||
loadTypeInfo(typeMapper, (ClassDescriptor) contextType, v);
|
||||
v.iconst(((TypeParameterDescriptor) declarationDescriptor).getIndex());
|
||||
v.invokevirtual("jet/typeinfo/TypeInfo", "getTypeParameter", "(I)Ljet/typeinfo/TypeInfo;");
|
||||
return;
|
||||
}
|
||||
throw new UnsupportedOperationException("don't know what this type parameter resolves to");
|
||||
loadTypeParameterTypeInfo(declarationDescriptor);
|
||||
return;
|
||||
}
|
||||
|
||||
final Type jvmType = typeMapper.mapType(jetType, OwnerKind.INTERFACE);
|
||||
@@ -1751,6 +1742,17 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private void loadTypeParameterTypeInfo(DeclarationDescriptor declarationDescriptor) {
|
||||
DeclarationDescriptor containingDeclaration = declarationDescriptor.getContainingDeclaration();
|
||||
if (containingDeclaration == contextType && contextType instanceof ClassDescriptor) {
|
||||
loadTypeInfo(typeMapper, (ClassDescriptor) contextType, v);
|
||||
v.iconst(((TypeParameterDescriptor) declarationDescriptor).getIndex());
|
||||
v.invokevirtual("jet/typeinfo/TypeInfo", "getTypeParameter", "(I)Ljet/typeinfo/TypeInfo;");
|
||||
return;
|
||||
}
|
||||
throw new UnsupportedOperationException("don't know what this type parameter resolves to");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitWhenExpression(JetWhenExpression expression) {
|
||||
JetExpression expr = expression.getSubjectExpression();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
class Foo() {}
|
||||
class Bar() {}
|
||||
|
||||
class InstanceChecker<T>() {
|
||||
fun check(obj: Any?) = obj is T
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val checker = InstanceChecker<Foo>()
|
||||
if (!checker.check(Foo())) return "fail 1"
|
||||
if (checker.check(Bar())) return "fail 2"
|
||||
return "OK"
|
||||
}
|
||||
@@ -73,6 +73,10 @@ public class TypeInfoTest extends CodegenTestCase {
|
||||
assertFalse((Boolean) foo.invoke(null));
|
||||
}
|
||||
|
||||
public void testIsTypeParameter() throws Exception {
|
||||
blackBoxFile("typeInfo/isTypeParameter.jet");
|
||||
}
|
||||
|
||||
public void testAsSafeWithGenerics() throws Exception {
|
||||
loadFile();
|
||||
Method foo = generateFunction();
|
||||
|
||||
Reference in New Issue
Block a user