diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java index c31b310ee73a..0def49c6d2d1 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/TypeChecker.java @@ -480,18 +480,21 @@ public static boolean isReferenceEqual(Object lhsValue, Object rhsValue) { } private static boolean isXMLValueRefEqual(XmlValue lhsValue, XmlValue rhsValue) { - if (lhsValue.getNodeType() == XmlNodeType.SEQUENCE && lhsValue.isSingleton()) { + boolean isLhsXmlSequence = lhsValue.getNodeType() == XmlNodeType.SEQUENCE; + boolean isRhsXmlSequence = rhsValue.getNodeType() == XmlNodeType.SEQUENCE; + + if (isLhsXmlSequence && isRhsXmlSequence) { + return isXMLSequenceRefEqual((XmlSequence) lhsValue, (XmlSequence) rhsValue); + } + if (isLhsXmlSequence && lhsValue.isSingleton()) { return ((XmlSequence) lhsValue).getChildrenList().get(0) == rhsValue; } - if (rhsValue.getNodeType() == XmlNodeType.SEQUENCE && rhsValue.isSingleton()) { + if (isRhsXmlSequence && rhsValue.isSingleton()) { return ((XmlSequence) rhsValue).getChildrenList().get(0) == lhsValue; } if (lhsValue.getNodeType() != rhsValue.getNodeType()) { return false; } - if (lhsValue.getNodeType() == XmlNodeType.SEQUENCE && rhsValue.getNodeType() == XmlNodeType.SEQUENCE) { - return isXMLSequenceRefEqual((XmlSequence) lhsValue, (XmlSequence) rhsValue); - } if (lhsValue.getNodeType() == XmlNodeType.TEXT && rhsValue.getNodeType() == XmlNodeType.TEXT) { return isEqual(lhsValue, rhsValue); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/ref_equal_and_not_equal_operation.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/ref_equal_and_not_equal_operation.bal index b598108f53b4..6e63ea100f3a 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/ref_equal_and_not_equal_operation.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/binaryoperations/ref_equal_and_not_equal_operation.bal @@ -465,8 +465,11 @@ function testXMLSequenceRefEquality() { xml x1 = xml `b`; xml x2 = x + x1; xml x3 = x + x1; + xml x4 = xml:concat(x); + xml x5 = xml:concat(x); test:assertTrue(x2 === x3); + test:assertTrue(x4 === x5); xml a1 = xml ``; xml a2 = xml ``;