diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java index 1cb3ec4f75e3..6d61f3b0e92c 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmTypeGen.java @@ -985,7 +985,8 @@ private void populateFunctionParameters(MethodVisitor mv, BInvokableTypeSymbol i } else { mv.visitInsn(ICONST_0); } - BInvokableSymbol bInvokableSymbol = invokableSymbol.defaultValues.get(paramSymbol.originalName.value); + BInvokableSymbol bInvokableSymbol = invokableSymbol.defaultValues.get( + Utils.decodeIdentifier(paramSymbol.name.value)); if (bInvokableSymbol == null) { mv.visitInsn(ACONST_NULL); } else { diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java index e6ff7fd6307e..0258d331b5ba 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/ClosureGenerator.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.desugar; +import io.ballerina.identifier.Utils; import io.ballerina.tools.diagnostics.Location; import org.ballerinalang.model.TreeBuilder; import org.ballerinalang.model.elements.Flag; @@ -555,7 +556,7 @@ private BLangExpression createClosureForDefaultValue(String closureName, String env.enclPkg.symbol.scope.define(function.symbol.name, function.symbol); env.enclPkg.functions.add(function); env.enclPkg.topLevelNodes.add(function); - symbol.defaultValues.put(paramName, varSymbol); + symbol.defaultValues.put(Utils.unescapeBallerina(paramName), varSymbol); return returnStmt.expr; } diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java index 5106ec89ec84..4a85ea735e30 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/desugar/Desugar.java @@ -17,6 +17,7 @@ */ package org.wso2.ballerinalang.compiler.desugar; +import io.ballerina.identifier.Utils; import io.ballerina.runtime.api.constants.RuntimeConstants; import io.ballerina.tools.diagnostics.Location; import org.apache.commons.lang3.StringEscapeUtils; @@ -6475,7 +6476,7 @@ private BLangStatementExpression createStmtExpr(BLangInvocation invocation) { continue; } - BInvokableSymbol invokableSymbol = defaultValues.get(paramName); + BInvokableSymbol invokableSymbol = defaultValues.get(Utils.unescapeBallerina(paramName)); BLangInvocation closureInvocation = getInvocation(invokableSymbol); for (int m = 0; m < invokableSymbol.params.size(); m++) { String langLibFuncParam = invokableSymbol.params.get(m).name.value; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Values.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Values.java index eb88e0a4d547..7a5403dedd75 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Values.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/nativeimpl/jvm/runtime/api/tests/Values.java @@ -477,6 +477,13 @@ public static BString getParameterNameFromResource(BTypedesc type) { return StringUtils.fromString(parameter.name); } + public static BString getParameterDefaultFunctionNameFromResource(BTypedesc type) { + BServiceType serviceType = (BServiceType) type.getDescribingType(); + ResourceMethodType resourceMethod = serviceType.getResourceMethods()[1]; + Parameter parameter = resourceMethod.getParameters()[0]; + return StringUtils.fromString(parameter.defaultFunctionName); + } + public static BArray getParamNamesFromObjectInit(BObject object) { ObjectType objectType = object.getType(); MethodType initMethodtype = objectType.getInitMethod(); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal index b75bb42eafa0..8b8fa9362fbf 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/runtime/api/identifier_utils/main.bal @@ -31,6 +31,10 @@ service class AccountService { email: "john.doe@email.com", phone: "1234567890" }; + resource function get packages(int? 'limit = ()) returns json => { + 'limit: 'limit, + body: "hello" + }; } public function main() { @@ -43,6 +47,8 @@ public function main() { function testFunctionParameters() { test:assertEquals(getParameterName(function(string account\-id) {}), "account-id"); test:assertEquals(getParameterNameFromResource(AccountService), "account-id"); + test:assertEquals(getParameterDefaultFunctionNameFromResource(AccountService), + "$AccountService_$get$packages_limit"); } function testIdentifierDecoding() { @@ -91,3 +97,7 @@ function getParameterName(function f) returns string = @java:Method { function getParameterNameFromResource(typedesc serviceObj) returns string = @java:Method { 'class: "org.ballerinalang.nativeimpl.jvm.runtime.api.tests.Values" } external; + +function getParameterDefaultFunctionNameFromResource(typedesc serviceObj) returns string = @java:Method { + 'class: "org.ballerinalang.nativeimpl.jvm.runtime.api.tests.Values" +} external;