diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java index 7230e27dba3..2627052c652 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java @@ -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"); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 1d73774dffa..186e94242d3 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -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 types = Collections.singletonList(new TypeProjection(Variance.INVARIANT, argument)); + return getIterableType(Variance.INVARIANT, argument); + } + + @NotNull + public JetType getIterableType(@NotNull Variance projectionType, @NotNull JetType argument) { + List types = Collections.singletonList(new TypeProjection(projectionType, argument)); return new JetTypeImpl( Collections.emptyList(), getIterable().getTypeConstructor(), diff --git a/compiler/testData/codegen/regressions/kt882.jet b/compiler/testData/codegen/regressions/kt882.jet new file mode 100644 index 00000000000..eee811f240b --- /dev/null +++ b/compiler/testData/codegen/regressions/kt882.jet @@ -0,0 +1,7 @@ +val _0 : Double = 0.0 +val _0dbl : Double = 0.dbl + +fun box() : String { + if(_0 != _0dbl) return "fail" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt887.jet b/compiler/testData/codegen/regressions/kt887.jet new file mode 100644 index 00000000000..ee1c57ec1d3 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt887.jet @@ -0,0 +1,5 @@ +class Book(val name: String) : Comparable { + override fun compareTo(other: Book) = name.compareTo(other.name) +} + +fun box() = if(Book("239").compareTo(Book("932")) != 0) "OK" else "fail" \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 72beaf1807f..51954800c69 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -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"); + } }