Skip to content

Commit

Permalink
Fix CCE in arrays with refered types
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Aug 20, 2024
1 parent b049daa commit b251984
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions ballerina/tests/fromXml_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -3585,3 +3585,26 @@ isolated function testDuplicateField() {
test:assertTrue(err4 is Error);
test:assertEquals((<Error> err4).message(), "duplicate field 'name'");
}

type Ports record {|
PortContent[] port;
|};

@Namespace {
prefix: "ns1",
uri: "example1.com"
}
type PortContent record {|
string \#content;
|};

@test:Config
isolated function testTypeRefArray() {
string s = string `
<A xmlns:ns1="example1.com" xmlns:ns2="example2.com">
<ns1:port>1</ns1:port>
<ns1:port>1</ns1:port>
</A>`;
Ports|error rec = parseString(s);
test:assertEquals(rec, {"port":[{"#content":"1"},{"#content":"1"}]});
}
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,10 @@ private void convertTextAndUpdateCurrentNode(BMap<BString, Object> currentNode,
@SuppressWarnings("unchecked")
private void addTextToCurrentNodeIfExpTypeIsArray(ArrayType fieldType, BString bFieldName, BString bText,
XmlParserData xmlParserData) {
int elementTypeTag = TypeUtils.getReferredType(fieldType.getElementType()).getTag();
Type referredType = TypeUtils.getReferredType(fieldType.getElementType());
int elementTypeTag = referredType.getTag();
switch (elementTypeTag) {
case TypeTags.RECORD_TYPE_TAG -> handleContentFieldInRecordType((RecordType) fieldType.getElementType(),
case TypeTags.RECORD_TYPE_TAG -> handleContentFieldInRecordType((RecordType) referredType,
bText, xmlParserData);
case TypeTags.ANYDATA_TAG, TypeTags.JSON_TAG -> {
BArray tempArr = (BArray) ((BMap<BString, Object>) xmlParserData.nodesStack.peek()).get(bFieldName);
Expand Down

0 comments on commit b251984

Please sign in to comment.