Skip to content

Commit

Permalink
Merge pull request #42274 from HindujaB/fix-service-fill-value
Browse files Browse the repository at this point in the history
Fix filler value check for service objects returning null
  • Loading branch information
warunalakshitha authored Mar 14, 2024
2 parents 7f858d4 + c725212 commit 5ccd423
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3398,6 +3398,7 @@ private static boolean hasFillerValue(Type type, List<Type> unanalyzedTypes) {
case TypeTags.FINITE_TYPE_TAG:
return checkFillerValue((BFiniteType) type);
case TypeTags.OBJECT_TYPE_TAG:
case TypeTags.SERVICE_TAG:
return checkFillerValue((BObjectType) type);
case TypeTags.RECORD_TYPE_TAG:
return checkFillerValue((BRecordType) type, unanalyzedTypes);
Expand Down Expand Up @@ -3557,20 +3558,16 @@ private static boolean checkFillerValue(BArrayType type, List<Type> unAnalyzedTy
}

private static boolean checkFillerValue(BObjectType type) {
if (type.getTag() == TypeTags.SERVICE_TAG) {
MethodType generatedInitMethod = type.getGeneratedInitMethod();
if (generatedInitMethod == null) {
// abstract objects doesn't have a filler value.
return false;
} else {
MethodType generatedInitMethod = type.getGeneratedInitMethod();
if (generatedInitMethod == null) {
// abstract objects doesn't have a filler value.
return false;
}
FunctionType initFuncType = generatedInitMethod.getType();
// Todo: check defaultable params of the init func as well
boolean noParams = initFuncType.getParameters().length == 0;
boolean nilReturn = getImpliedType(initFuncType.getReturnType()).getTag() == TypeTags.NULL_TAG;
return noParams && nilReturn;
}
FunctionType initFuncType = generatedInitMethod.getType();
boolean noParams = initFuncType.getParameters().length == 0;
boolean nilReturn = getImpliedType(initFuncType.getReturnType()).getTag() == TypeTags.NULL_TAG;
return noParams && nilReturn;

}

private static boolean checkFillerValue(BFiniteType type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ public function main() {
tesOneDimensionalArrayWithConstantSizeReferenceFill();
tesTwoDimensionalArrayWithConstantSizeReferenceFill();
testAnonRecordTypeWithDefaultValueFill();
testServiceClassArrayFilling();
// testObjectArrayFillingWithDefaultValues();
}

Expand All @@ -252,3 +253,14 @@ function assertEqualPanic(anydata expected, anydata actual, string message = "Va
panic error(message + " Expected : " + expected.toString() + " Actual : " + actual.toString());
}
}

service class Class1 {}

service class Class2 {}

public function testServiceClassArrayFilling() {
[Class1, Class2] interceptors = [];
assertEqualPanic(2, interceptors.length());
assertEqualPanic(true, interceptors[0] is Class1);
assertEqualPanic(true, interceptors[1] is Class2);
}

0 comments on commit 5ccd423

Please sign in to comment.