KT_887 fix. jet.Comparable mapped to j.l.Comparable

This commit is contained in:
Alex Tkachman
2012-01-03 12:34:12 +02:00
parent e576423c8e
commit 2ec54436c5
5 changed files with 44 additions and 1 deletions
@@ -46,6 +46,7 @@ public class JetTypeMapper {
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_STRING_TYPE = Type.getObjectType("java/lang/String");
private static final Type JL_COMPARABLE_TYPE = Type.getObjectType("java/lang/Comparable");
public static final Type ARRAY_INT_TYPE = Type.getType(int[].class);
public static final Type ARRAY_LONG_TYPE = Type.getType(long[].class);
@@ -297,6 +298,15 @@ public class JetTypeMapper {
throw new IllegalStateException("should not compile an error type");
}
if (standardLibrary.getComparable().equals(descriptor)) {
if (jetType.getArguments().size() != 1) {
throw new UnsupportedOperationException("Comparable must have one type argument");
}
// todo signature
return JL_COMPARABLE_TYPE;
}
if (standardLibrary.getArray().equals(descriptor)) {
if (jetType.getArguments().size() != 1) {
throw new UnsupportedOperationException("arrays must have one type argument");
@@ -65,6 +65,7 @@ public class JetStandardLibrary {
private ClassDescriptor arrayClass;
private ClassDescriptor iterableClass;
private ClassDescriptor typeInfoClass;
private ClassDescriptor comparableClass;
private JetType byteType;
private JetType charType;
@@ -168,6 +169,7 @@ public class JetStandardLibrary {
this.arrayClass = (ClassDescriptor) libraryScope.getClassifier("Array");
this.iterableClass = (ClassDescriptor) libraryScope.getClassifier("Iterable");
this.comparableClass = (ClassDescriptor) libraryScope.getClassifier("Comparable");
// typeInfoNamespace = libraryScope.getNamespace("typeinfo");
this.typeInfoClass = (ClassDescriptor) libraryScope.getClassifier("TypeInfo");
this.typeInfoFunction = libraryScope.getFunctions("typeinfo");
@@ -297,6 +299,12 @@ public class JetStandardLibrary {
return iterableClass;
}
@NotNull
public ClassDescriptor getComparable() {
initStdClasses();
return comparableClass;
}
// public NamespaceDescriptor getTypeInfoNamespace() {
// initStdClasses();
// return typeInfoNamespace;
@@ -392,7 +400,12 @@ public class JetStandardLibrary {
@NotNull
public JetType getIterableType(@NotNull JetType argument) {
List<TypeProjection> types = Collections.singletonList(new TypeProjection(Variance.INVARIANT, argument));
return getIterableType(Variance.INVARIANT, argument);
}
@NotNull
public JetType getIterableType(@NotNull Variance projectionType, @NotNull JetType argument) {
List<TypeProjection> types = Collections.singletonList(new TypeProjection(projectionType, argument));
return new JetTypeImpl(
Collections.<AnnotationDescriptor>emptyList(),
getIterable().getTypeConstructor(),
@@ -0,0 +1,7 @@
val _0 : Double = 0.0
val _0dbl : Double = 0.dbl
fun box() : String {
if(_0 != _0dbl) return "fail"
return "OK"
}
@@ -0,0 +1,5 @@
class Book(val name: String) : Comparable<Book> {
override fun compareTo(other: Book) = name.compareTo(other.name)
}
fun box() = if(Book("239").compareTo(Book("932")) != 0) "OK" else "fail"
@@ -355,4 +355,12 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testKt877 () {
blackBoxFile("regressions/kt877.jet");
}
public void testKt882 () {
// blackBoxFile("regressions/kt882.jet");
}
public void testKt887 () {
blackBoxFile("regressions/kt887.jet");
}
}