diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java index da3c31f9d93b..41e0949ef222 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/BIRGen.java @@ -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; @@ -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(); } } @@ -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; diff --git a/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibValueTest.java b/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibValueTest.java index d44f848941ac..cec4adb5d0bd 100644 --- a/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibValueTest.java +++ b/langlib/langlib-test/src/test/java/org/ballerinalang/langlib/test/LangLibValueTest.java @@ -379,7 +379,7 @@ public Object[] cloneWithTypeFunctions() { "testConvertToUnionWithAmbiguousMemberTypes", "testConvertingToReferenceTypes", "testCloneWithTypeTableToAnydata", "testUnionNestedTypeConversionErrors", "testCloneWithTypeToUnionOfTypeReference", "testCloneWithTypeToTableNegative", - "testCloneWithTypeToRecordWithIntersectingUnionMembers" + "testCloneWithTypeToRecordWithIntersectingUnionMembers", "testCloneWithTypeToRecordWithSpecialChars" }; } diff --git a/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal b/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal index 7ca8e2352c1f..d004983917af 100644 --- a/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal +++ b/langlib/langlib-test/src/test/resources/test-src/valuelib_test.bal @@ -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 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";