KT-2210: Array<Array<T>> type mapping

This commit is contained in:
Alex Tkachman
2012-08-04 22:52:02 +03:00
parent 4e0e7fb943
commit fcab204459
4 changed files with 20 additions and 62 deletions
@@ -2567,18 +2567,6 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
if (isArray) {
gen(args.get(0), Type.INT_TYPE);
v.newarray(boxType(asmType(arrayType.getArguments().get(0).getType())));
/*
JetType elementType = typeMapper.getGenericsElementType(arrayType);
if (elementType != null) {
generateTypeInfo(elementType, null);
gen(args.get(0), Type.INT_TYPE);
v.invokevirtual("jet/TypeInfo", "newArray", "(I)[Ljava/lang/Object;");
}
else {
gen(args.get(0), Type.INT_TYPE);
v.newarray(boxType(asmType(arrayType.getArguments().get(0).getType())));
}
*/
}
else {
Type type = typeMapper.mapType(arrayType, MapTypeMode.VALUE);
@@ -61,7 +61,6 @@ public class JetTypeMapper {
public static final Type TYPE_NOTHING = Type.getObjectType("jet/Nothing");
public static final Type JL_NUMBER_TYPE = Type.getObjectType("java/lang/Number");
public static final Type JL_STRING_BUILDER = Type.getObjectType("java/lang/StringBuilder");
public static final Type JL_ARRAY_LIST = Type.getObjectType("java/util/ArrayList");
public static final Type JL_STRING_TYPE = Type.getObjectType("java/lang/String");
public static final Type JL_CHAR_SEQUENCE_TYPE = Type.getObjectType("java/lang/CharSequence");
private static final Type JL_COMPARABLE_TYPE = Type.getObjectType("java/lang/Comparable");
@@ -302,19 +301,6 @@ public class JetTypeMapper {
return mapType(jetType, signatureVisitor, MapTypeMode.VALUE);
}
private String getStableNameForObject(JetObjectDeclaration object, DeclarationDescriptor descriptor) {
String local = getLocalNameForObject(object);
if (local == null) return null;
ClassDescriptor containingClass = getContainingClass(descriptor);
if (containingClass != null) {
return getClassFQName(containingClass).getInternalName() + "$" + local;
}
else {
return getFQName(getContainingNamespace(descriptor)) + "/" + local;
}
}
public static String getLocalNameForObject(JetObjectDeclaration object) {
PsiElement parent = object.getParent();
if (parent instanceof JetClassObject) {
@@ -386,18 +372,6 @@ public class JetTypeMapper {
return name.getIdentifier();
}
private static ClassDescriptor getContainingClass(DeclarationDescriptor descriptor) {
DeclarationDescriptor parent = descriptor.getContainingDeclaration();
if (parent == null || parent instanceof ClassDescriptor) return (ClassDescriptor) parent;
return getContainingClass(parent);
}
private static NamespaceDescriptor getContainingNamespace(DeclarationDescriptor descriptor) {
DeclarationDescriptor parent = descriptor.getContainingDeclaration();
if (parent == null || parent instanceof NamespaceDescriptor) return (NamespaceDescriptor) parent;
return getContainingNamespace(parent);
}
@NotNull
public Type mapType(@NotNull final JetType jetType, @NotNull MapTypeMode kind) {
return mapType(jetType, null, kind);
@@ -531,6 +505,7 @@ public class JetTypeMapper {
Type type = mapType(((TypeParameterDescriptor) descriptor).getUpperBoundsAsType(), kind);
if (signatureVisitor != null) {
TypeParameterDescriptor typeParameterDescriptor = (TypeParameterDescriptor) jetType.getConstructor().getDeclarationDescriptor();
assert typeParameterDescriptor != null;
signatureVisitor.writeTypeVariable(typeParameterDescriptor.getName(), jetType.isNullable(), type);
}
checkValidType(type);
@@ -565,11 +540,10 @@ public class JetTypeMapper {
private void checkValidType(@NotNull Type type) {
if (!mapBuiltinsToJava) {
String descriptor = type.getDescriptor();
if (descriptor.equals("Ljava/lang/Object;")) {
return;
}
else if (descriptor.startsWith("Ljava/")) {
throw new IllegalStateException("builtins must not reference java.* classes: " + descriptor);
if (!descriptor.equals("Ljava/lang/Object;")) {
if (descriptor.startsWith("Ljava/")) {
throw new IllegalStateException("builtins must not reference java.* classes: " + descriptor);
}
}
}
}
@@ -849,7 +823,6 @@ public class JetTypeMapper {
if(kind == OwnerKind.TRAIT_IMPL) {
ClassDescriptor containingDeclaration = (ClassDescriptor) parentDescriptor;
assert containingDeclaration != null;
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.IMPL);
signatureWriter.writeParameterTypeEnd();
@@ -890,7 +863,6 @@ public class JetTypeMapper {
String name = PropertyCodegen.setterName(descriptor.getName());
if (kind == OwnerKind.TRAIT_IMPL) {
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
assert containingDeclaration != null;
signatureWriter.writeParameterType(JvmMethodParameterKind.THIS);
mapType(containingDeclaration.getDefaultType(), signatureWriter, MapTypeMode.VALUE);
signatureWriter.writeParameterTypeEnd();
@@ -1048,7 +1020,7 @@ public class JetTypeMapper {
}
}
private boolean isForceReal(JvmClassName className) {
private static boolean isForceReal(JvmClassName className) {
return JvmPrimitiveType.getByWrapperClass(className) != null
|| className.getFqName().getFqName().equals("java.lang.String")
|| className.getFqName().getFqName().equals("java.lang.CharSequence")
@@ -1057,22 +1029,8 @@ public class JetTypeMapper {
|| className.getFqName().getFqName().equals("java.lang.Comparable");
}
public boolean isGenericsArray(JetType type) {
DeclarationDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
if (declarationDescriptor instanceof TypeParameterDescriptor) {
return true;
}
if (JetStandardLibraryNames.ARRAY.is(type)) {
return isGenericsArray(type.getArguments().get(0).getType());
}
return false;
}
public JetType getGenericsElementType(JetType arrayType) {
JetType type = arrayType.getArguments().get(0).getType();
return isGenericsArray(type) ? type : null;
public static boolean isGenericsArray(JetType type) {
return JetStandardLibraryNames.ARRAY.is(type) && type.getArguments().get(0).getType().getConstructor().getDeclarationDescriptor() instanceof TypeParameterDescriptor;
}
public Type getSharedVarType(DeclarationDescriptor descriptor) {
@@ -0,0 +1,7 @@
class A<T>(t: Array<Array<T>>) {
val a:Array<Array<T>> = t
}
fun main(args : Array<String>) {
A<Int>(array()) // <- java.lang.VerifyError: (class: A, method: getA signature: ()[[Ljava/lang/Object;) Wrong return type in function
}
@@ -352,4 +352,9 @@ public class StdlibTest extends CodegenTestCase {
public void test1779() {
blackBoxFile("regressions/kt1779.kt");
}
public void testKt2210() throws Exception {
blackBoxFile("regressions/kt2210.kt");
// System.out.println(generateToText());
}
}