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:
+2
-1
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -37,5 +37,7 @@ fun box(): String {
|
||||
assertNotEquals(ho1, ho2)
|
||||
assertNotEquals(ho1, ho3)
|
||||
|
||||
assertTrue((d1 : Any) != "")
|
||||
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user