Correct equals for tuples.

This commit is contained in:
Pavel V. Talanov
2012-07-31 13:15:54 +04:00
parent e0ff877b47
commit 49e51220d7
3 changed files with 46 additions and 1 deletions
@@ -36,6 +36,10 @@ public final class TupleTest extends SingleFileTranslationTest {
fooBoxTest();
}
public void testTuplesEquals() throws Exception {
fooBoxTest();
}
}
+11 -1
View File
@@ -23,7 +23,17 @@ var kotlin = {set:function (receiver, key, value) {
"use strict";
Kotlin.equals = function (obj1, obj2) {
if ((obj1 === null)|| (obj1 === undefined)) return obj2 === null;
if ((obj1 === null) || (obj1 === undefined)) return obj2 === null;
if (obj1 instanceof Array) {
if (!(obj2 instanceof Array)) return false;
if (obj1.length != obj2.length) return false;
for (var i = 0; i < obj1.length; i++) {
if (!Kotlin.equals(obj1[i], obj2[i])) {
return false;
}
}
return true;
}
if (typeof obj1 == "object") {
if (obj1.equals !== undefined) {
return obj1.equals(obj2);
@@ -0,0 +1,31 @@
package foo
class A(val i: Int = 2) {
fun equals(other: Any?): Boolean {
if (other !is A) {
return false
}
return i % 2 == other.i % 2
}
}
fun box(): Boolean {
val c = #(3, 1)
if (c != #(3, 1)) {
return false
}
if (c == #(1, 3)) {
return false
}
val b = #(A(2), A(1))
if (b != #(A(0), A(3))) {
return false
}
if (b == #(A(2), A(4))) {
return false
}
if (#("aaa") != #("aaa")) {
return false
}
return true
}