Skip to content

Commit

Permalink
Merge pull request #43335 from HindujaB/fix-object-virtual-call
Browse files Browse the repository at this point in the history
Fix immutable object virtual call getting no such method error
  • Loading branch information
warunalakshitha authored Sep 20, 2024
2 parents 78ff304 + c7be55e commit 547e819
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,16 @@ public static String cleanupPathSeparators(String name) {

public static String rewriteVirtualCallTypeName(String value, BType objectType) {
objectType = getImpliedType(objectType);
// The call name will be in the format of`objectTypeName.funcName` for attached functions of imported modules.
// Therefore, We need to remove the type name.
if (!objectType.tsymbol.name.value.isEmpty() && value.startsWith(objectType.tsymbol.name.value)) {
value = value.replace(objectType.tsymbol.name.value + ".", "").trim();
String typeName = objectType.tsymbol.name.value;
Name originalName = objectType.tsymbol.originalName;
if (value.startsWith(typeName)) {
// The call name will be in the format of`objectTypeName.funcName` for attached functions of imported
// modules. Therefore, We need to remove the type name.
value = value.replace(typeName + ".", "").trim();
} else if (originalName != null && value.startsWith(originalName.value)) {
// The call name will be in the format of`objectTypeOriginalName.funcName` for attached functions of
// object definitions. Therefore, We need to remove it.
value = value.replace(originalName + ".", "").trim();
}
return Utils.encodeFunctionIdentifier(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public Object[] readOnlyObjectTests() {
"testReadOnlyServiceClass",
"testReadOnlyClassIntersectionWithMismatchedQualifiersRuntimeNegative",
"testReadOnlyClassIntersectionWithValidQualifiers",
"testRecursiveObjectArrayReadonlyClone"
"testRecursiveObjectArrayReadonlyClone",
"testReadonlyObjectMethodCall"
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,21 @@ public function testRecursiveObjectArrayReadonlyClone() {
assertTrue(x is readonly & Obj[]);
}

public function testReadonlyObjectMethodCall() {
File file = new VirtualFile();
string filename = file.filename();
assertEquality("File Name", filename);
}

public type File readonly & object {
public function filename() returns string;
};

public readonly class VirtualFile {
*File;
public function filename() returns string => "File Name";
}

const ASSERTION_ERROR_REASON = "AssertionError";

function assertTrue(any|error actual) {
Expand Down

0 comments on commit 547e819

Please sign in to comment.