Before comparing types of data class objects in dataClass.equals ensure that the other comparand is an object too, otherwise it may fail on Rhino.

This commit is contained in:
Ilya Gorbunov
2015-09-03 21:57:06 +03:00
parent f6c9d63c46
commit c82c914c5d
2 changed files with 4 additions and 1 deletions
@@ -155,6 +155,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
JsExpression referenceEqual = JsAstUtils.equality(JsLiteral.THIS, new JsNameRef(paramName));
JsExpression isNotNull = JsAstUtils.inequality(new JsNameRef(paramName), JsLiteral.NULL);
JsExpression otherIsObject = JsAstUtils.typeof(paramName.makeRef(), context.program().getStringLiteral("object"));
JsExpression prototypeEqual =
JsAstUtils.equality(new JsInvocation(new JsNameRef("getPrototypeOf", new JsNameRef("Object")), JsLiteral.THIS),
new JsInvocation(new JsNameRef("getPrototypeOf", new JsNameRef("Object")), new JsNameRef(paramName)));
@@ -175,7 +176,7 @@ class JsDataClassGenerator extends DataClassMethodGenerator {
assert fieldChain != null;
JsExpression returnExpression =
JsAstUtils.or(referenceEqual, JsAstUtils.and(isNotNull, JsAstUtils.and(prototypeEqual, fieldChain)));
JsAstUtils.or(referenceEqual, JsAstUtils.and(isNotNull, JsAstUtils.and(otherIsObject, JsAstUtils.and(prototypeEqual, fieldChain))));
functionObj.getBody().getStatements().add(new JsReturn(returnExpression));
}
+2
View File
@@ -37,5 +37,7 @@ fun box(): String {
assertNotEquals(ho1, ho2)
assertNotEquals(ho1, ho3)
assertTrue((d1 : Any) != "")
return "OK"
}