diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java index d7c94ff5c2fc..72bd2946d647 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/bir/codegen/JvmCodeGenUtil.java @@ -202,7 +202,7 @@ public static String cleanupPathSeparators(String name) { } public static String rewriteVirtualCallTypeName(String value, BType objectType) { - return Utils.encodeFunctionIdentifier(cleanupObjectTypeName(value, objectType)); + return Utils.encodeFunctionIdentifier(cleanupObjectTypeName(value, getImpliedType(objectType))); } private static String cleanupBalExt(String name) { @@ -518,23 +518,18 @@ public static String generateReturnType(BType bType) { } } - static String cleanupObjectTypeName(String typeName, BType objectType) { - if (!objectType.tsymbol.name.value.equals("") && typeName.startsWith(objectType.tsymbol.name.value)) { - typeName = typeName.replace(objectType.tsymbol.name.value + ".", "").trim(); + static String cleanupObjectTypeName(String callName, BType objectType) { + // For attached functions from another module the call name will be in the format `objectTypeName.funcName`. + // We need to remove the type name. + if (!objectType.tsymbol.name.value.isEmpty() && callName.startsWith(objectType.tsymbol.name.value)) { + callName = callName.replace(objectType.tsymbol.name.value + ".", "").trim(); } - int index = typeName.lastIndexOf("."); // Internal type names can contain dots hence use the `lastIndexOf` - int typeNameLength = typeName.length(); - if (index > 1 && typeName.charAt(index - 1) == '\\') { // Methods can contain escaped characters - return typeName; - } else if (index > 0 && index != typeNameLength - 1) { // Resource method name can contain . at the end - return typeName.substring(index + 1); - } else if (index > 0) { - // We will reach here for resource methods eg: (MyClient8.$get$.) - index = typeName.substring(0, typeNameLength - 1).lastIndexOf("."); // Index of the . before the last . - return typeName.substring(index + 1); + // For attached functions from another module where the type is an anonType, the call name will be in + // the format `(objectTypeName).funcName`. We need to remove the type name. + if (callName.startsWith("(") && callName.contains(").")) { + callName = callName.substring(callName.indexOf(").") + 2); } - - return typeName; + return callName; } public static void loadChannelDetails(MethodVisitor mv, List channels,