From 9eecf22e15dda34f42bf7594ff13dbad3145d617 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 28 Nov 2012 17:03:56 +0400 Subject: [PATCH] Booleans are no longer Comparable --- .../org/jetbrains/jet/codegen/intrinsics/CompareTo.java | 3 --- compiler/frontend/src/jet/Library.jet | 4 +--- compiler/testData/builtin-classes.txt | 3 +-- .../diagnostics/tests/library/BooleanIsNotComparable.kt | 8 ++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ .../tests/org/jetbrains/jet/types/JetTypeCheckerTest.java | 2 +- runtime/src/jet/runtime/Intrinsics.java | 4 ---- 7 files changed, 16 insertions(+), 13 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/library/BooleanIsNotComparable.kt diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/CompareTo.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/CompareTo.java index 17cd51f4f26..96f38c22064 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/CompareTo.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/CompareTo.java @@ -51,9 +51,6 @@ public class CompareTo implements IntrinsicMethod { else if (receiver.type == Type.INT_TYPE) { v.invokestatic("jet/runtime/Intrinsics", "compare", "(II)I"); } - else if (receiver.type == Type.BOOLEAN_TYPE) { - v.invokestatic("jet/runtime/Intrinsics", "compare", "(ZZ)I"); - } else if (receiver.type == Type.LONG_TYPE) { v.invokestatic("jet/runtime/Intrinsics", "compare", "(JJ)I"); } diff --git a/compiler/frontend/src/jet/Library.jet b/compiler/frontend/src/jet/Library.jet index b875c86c440..b065ab24d87 100644 --- a/compiler/frontend/src/jet/Library.jet +++ b/compiler/frontend/src/jet/Library.jet @@ -28,7 +28,7 @@ public trait Hashable { public fun equals(other : Any?) : Boolean } -public class Boolean : Comparable { +public class Boolean { public fun not() : Boolean public fun and(other : Boolean) : Boolean @@ -38,8 +38,6 @@ public class Boolean : Comparable { public fun xor(other : Boolean) : Boolean public fun equals(other : Any?) : Boolean - - public override fun compareTo(that : Boolean) : Int } public trait CharSequence { diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index e7521dc8d1b..f80806eb6a2 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -13,10 +13,9 @@ public final class jet.Array : jet.Any { public final fun set(/*0*/ index: jet.Int, /*1*/ value: T): jet.Tuple0 public final val size: jet.Int } -public final class jet.Boolean : jet.Comparable { +public final class jet.Boolean : jet.Any { public final /*constructor*/ fun (): jet.Boolean public final fun and(/*0*/ other: jet.Boolean): jet.Boolean - public open override /*1*/ fun compareTo(/*0*/ that: jet.Boolean): jet.Int public final fun equals(/*0*/ other: jet.Any?): jet.Boolean public final fun not(): jet.Boolean public final fun or(/*0*/ other: jet.Boolean): jet.Boolean diff --git a/compiler/testData/diagnostics/tests/library/BooleanIsNotComparable.kt b/compiler/testData/diagnostics/tests/library/BooleanIsNotComparable.kt new file mode 100644 index 00000000000..02a6b985fea --- /dev/null +++ b/compiler/testData/diagnostics/tests/library/BooleanIsNotComparable.kt @@ -0,0 +1,8 @@ +fun foo(x: Boolean) { + x < x + x <= x + x > x + x >= x + x == x + x.compareTo(x) +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 74dd1487883..b87f789f49b 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2386,6 +2386,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/library"), "kt", true); } + @TestMetadata("BooleanIsNotComparable.kt") + public void testBooleanIsNotComparable() throws Exception { + doTest("compiler/testData/diagnostics/tests/library/BooleanIsNotComparable.kt"); + } + @TestMetadata("Collections.kt") public void testCollections() throws Exception { doTest("compiler/testData/diagnostics/tests/library/Collections.kt"); diff --git a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java index 3d52487265b..7c50a3571ba 100644 --- a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java @@ -207,7 +207,7 @@ public class JetTypeCheckerTest extends JetLiteFixture { assertCommonSupertype("Derived_T", "DDerived_T", "DDerived1_T"); assertCommonSupertype("Comparable<*>", "Comparable", "Comparable"); - assertCommonSupertype("Base_T>", "Base_T", "Base_T"); + assertCommonSupertype("Base_T>", "Base_T", "Base_T"); assertCommonSupertype("Base_T", "Base_T", "Base_T"); assertCommonSupertype("Base_T", "Derived_T", "Base_T"); assertCommonSupertype("Base_T", "Derived_T", "Base_T"); diff --git a/runtime/src/jet/runtime/Intrinsics.java b/runtime/src/jet/runtime/Intrinsics.java index dedb273c1a5..577f2ddcd87 100644 --- a/runtime/src/jet/runtime/Intrinsics.java +++ b/runtime/src/jet/runtime/Intrinsics.java @@ -80,10 +80,6 @@ public class Intrinsics { return (thisVal R stupidSync(Object lock, Function0 block) { synchronized (lock) { return block.invoke();