Skip to content

Commit

Permalink
Merge pull request #41640 from HindujaB/fix-record-special-char
Browse files Browse the repository at this point in the history
Fix value conversion error for inline record creation with special characters
  • Loading branch information
warunalakshitha authored Nov 23, 2023
2 parents a33bee3 + 4c81b9e commit f59419a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.wso2.ballerinalang.compiler.bir;

import io.ballerina.identifier.Utils;
import io.ballerina.tools.diagnostics.Location;
import io.ballerina.tools.text.LinePosition;
import io.ballerina.tools.text.LineRange;
Expand Down Expand Up @@ -363,11 +364,11 @@ public void visit(BLangTypeDefinition astTypeDefinition) {
BType type = getDefinedType(astTypeDefinition);
BType referredType = Types.getImpliedType(type);
BSymbol symbol = astTypeDefinition.symbol;
Name displayName = symbol.name;
String displayName = symbol.name.value;
if (referredType.tag == TypeTags.RECORD) {
BRecordType recordType = (BRecordType) referredType;
if (recordType.shouldPrintShape()) {
displayName = new Name(recordType.toString());
displayName = recordType.toString();
}
}

Expand All @@ -378,7 +379,7 @@ public void visit(BLangTypeDefinition astTypeDefinition) {
type,
new ArrayList<>(),
symbol.origin.toBIROrigin(),
displayName,
new Name(Utils.unescapeBallerina(displayName)),
symbol.originalName);
if (symbol.tag == SymTag.TYPE_DEF) {
BTypeReferenceType referenceType = ((BTypeDefinitionSymbol) symbol).referenceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public Object[] cloneWithTypeFunctions() {
"testConvertToUnionWithAmbiguousMemberTypes", "testConvertingToReferenceTypes",
"testCloneWithTypeTableToAnydata", "testUnionNestedTypeConversionErrors",
"testCloneWithTypeToUnionOfTypeReference", "testCloneWithTypeToTableNegative",
"testCloneWithTypeToRecordWithIntersectingUnionMembers"
"testCloneWithTypeToRecordWithIntersectingUnionMembers", "testCloneWithTypeToRecordWithSpecialChars"
};
}

Expand Down
33 changes: 33 additions & 0 deletions langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -4645,6 +4645,39 @@ function testLast() {
assertTrue([] == value:last(ar1, ar));
}

public type Copybook record {
DFH\-COMMAREA DFH\-COMMAREA?;
};

public type DFH\-COMMAREA record {
record {
string MI\-HDR\-VERSION?;
string MI\-HDR\-MSGID?;
string MI\-HDR\-LOGGINGID?;
record {
string MI\-HDR\-REPLYQMGR?;
}[2] MI\-HDR\-REPLYSTACK?;
} BROKER\-MESSAGE\-AREA?;
};

function testCloneWithTypeToRecordWithSpecialChars() {
string s = string `{
"DFH-COMMAREA": {
"BROKER-MESSAGE-AREA": {
"MI-HDR-VERSION": "2",
"MI-HDR-MSGID":"3238763233323598798798712321187612",
"MI-HDR-LOGGINGID": "Z5118761-Z"
}
}
}`;
json rec = checkpanic value:fromJsonString(s);
map<json> mapJson = checkpanic rec.ensureType();
Copybook|error dfh\-commarea = mapJson.cloneWithType();
assertTrue(dfh\-commarea is Copybook);
Copybook cb = checkpanic dfh\-commarea.ensureType();
assertEquality(cb.DFH\-COMMAREA?.BROKER\-MESSAGE\-AREA.toString(), string `{"MI-HDR-VERSION":"2","MI-HDR-MSGID":"3238763233323598798798712321187612","MI-HDR-LOGGINGID":"Z5118761-Z"}`);
}

type AssertionError distinct error;

const ASSERTION_ERROR_REASON = "AssertionError";
Expand Down

0 comments on commit f59419a

Please sign in to comment.