From c5f53df70d5f95fdaa6c97ac99ec41cc75139561 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Tue, 16 Jul 2013 16:19:34 +0400 Subject: [PATCH] JS backend: fixed wrong result when compare null and undefined using Kotlin.equals. --- .../expression/equals/cases/equalsNullOrUndefined.kt | 7 +++++++ js/js.translator/testFiles/kotlin_lib.js | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/js/js.translator/testFiles/expression/equals/cases/equalsNullOrUndefined.kt b/js/js.translator/testFiles/expression/equals/cases/equalsNullOrUndefined.kt index 03dd20515b7..706fb6db4b7 100644 --- a/js/js.translator/testFiles/expression/equals/cases/equalsNullOrUndefined.kt +++ b/js/js.translator/testFiles/expression/equals/cases/equalsNullOrUndefined.kt @@ -1,11 +1,18 @@ package foo +native val undefined: Any = noImpl + fun box() : String { val a: Int? = null val r = a == null if (!r || a != null) return "wrong result on simple nullable check" + //force using Kotlin.equals + val t = null + if (t != undefined) + return "wrong result when compare null and undefined using Kotlin.equals" + var i = 0; fun foo(): Int? = ++i; if (foo() == null) diff --git a/js/js.translator/testFiles/kotlin_lib.js b/js/js.translator/testFiles/kotlin_lib.js index d376e093b3e..19c8d1181d8 100644 --- a/js/js.translator/testFiles/kotlin_lib.js +++ b/js/js.translator/testFiles/kotlin_lib.js @@ -36,8 +36,8 @@ var kotlin = {set:function (receiver, key, value) { (function () { Kotlin.equals = function (obj1, obj2) { - if (obj1 === null || obj1 === undefined) { - return obj2 === null; + if (obj1 == null) { + return obj2 == null; } if (obj1 instanceof Array) {