Make enum classes comparable
#KT-3727 Fixed
This commit is contained in:
@@ -46,4 +46,8 @@ public class EnumTest extends SingleFileTranslationTest {
|
||||
public void testSuperCallInEnumLiteral() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testEnumIsComparable() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package foo
|
||||
|
||||
enum class A {
|
||||
one
|
||||
two
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = A.one.compareTo(A.two)
|
||||
if (x != -1) return "Fail cmp(one, two) = $x"
|
||||
val y = A.two.compareTo(A.one)
|
||||
if (y != 1) return "Fail cmp(two, one) = $y"
|
||||
|
||||
if (!(A.one < A.two)) return "Fail !(one < two)"
|
||||
if (A.one >= A.two) return "Fail one >= two"
|
||||
|
||||
if (!(A.two > A.one)) return "Fail !(two > one)"
|
||||
if (A.two <= A.one) return "Fail two <= one"
|
||||
|
||||
val z = A.one.compareTo(A.one)
|
||||
if (z != 0) return "Fail cmp(one, one) = $z"
|
||||
|
||||
return "OK"
|
||||
}
|
||||
@@ -23,6 +23,7 @@ fun box(): String {
|
||||
|
||||
val ok2 = Simple.valueOf("OK")
|
||||
if (!ok2.equals(ok)) return "ok2 not equal ok"
|
||||
if (ok2.hashCode() != ok.hashCode()) return "hash(ok2) not equal hash(ok)"
|
||||
if (!ok2.identityEquals(ok)) return "ok2 not identity equal ok"
|
||||
|
||||
|
||||
@@ -33,6 +34,7 @@ fun box(): String {
|
||||
if (A.c.toString() != "c") return "A.c.toString() != c, it: ${A.c.toString()}"
|
||||
if (A.valueOf("b") != A.b) return "A.valueOf('b') != A.b"
|
||||
if (A.a == A.b) return "A.a == A.b"
|
||||
if (A.a.hashCode() == A.b.hashCode()) return "hash(A.a) == hash(A.b)"
|
||||
|
||||
if (A.a.name() != "a") return "A.a.name() != a, it: ${A.a.name()}"
|
||||
if (A.b.name() != "b") return "A.b.name() != b, it: ${A.b.name()}"
|
||||
|
||||
@@ -292,6 +292,15 @@
|
||||
ordinal: function () {
|
||||
return this.ordinal$;
|
||||
},
|
||||
equals_za3rmp$: function (o) {
|
||||
return this === o;
|
||||
},
|
||||
hashCode: function () {
|
||||
return getObjectHashCode(this);
|
||||
},
|
||||
compareTo_za3rmp$: function (o) {
|
||||
return this.ordinal$ < o.ordinal$ ? -1 : this.ordinal$ > o.ordinal$ ? 1 : 0;
|
||||
},
|
||||
toString: function () {
|
||||
return this.name();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user