Skip to content

Commit

Permalink
Merge pull request #43683 from gimantha/2201.11.0-stage-#40606
Browse files Browse the repository at this point in the history
[2201.11.0 stage] Fix Resource access that are not ambiguous are reported as ambiguous access
  • Loading branch information
chiranSachintha authored Dec 4, 2024
2 parents f762dae + 4dd1896 commit 0d1e483
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4083,17 +4083,28 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn
handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments,
resourceAccessInvocation.name.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE_METHOD, data,
resourceAccessInvocation.name, lhsExprType);
return;
} else if (targetResourceFuncCount > 1) {
handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, resourceAccessInvocation.pos,
DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED, data, lhsExprType);
} else {
BResourceFunction targetResourceFunc = resourceFunctions.get(0);
checkExpr(resourceAccessInvocation.resourceAccessPathSegments,
getResourcePathType(targetResourceFunc.pathSegmentSymbols), data);
resourceAccessInvocation.symbol = targetResourceFunc.symbol;
resourceAccessInvocation.targetResourceFunc = targetResourceFunc;
checkResourceAccessParamAndReturnType(resourceAccessInvocation, targetResourceFunc, data);
//Filter the resource function with identifier segment
Optional<BResourceFunction> first = resourceFunctions
.stream().filter(func -> func.pathSegmentSymbols.stream()
.allMatch(segment -> segment.kind == SymbolKind.RESOURCE_PATH_IDENTIFIER_SEGMENT))
.findFirst();
if (first.isPresent()) {
resourceFunctions = new ArrayList<>(List.of(first.get()));
} else {
handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments,
resourceAccessInvocation.pos, DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED,
data, lhsExprType);
return;
}
}
BResourceFunction targetResourceFunc = resourceFunctions.get(0);
checkExpr(resourceAccessInvocation.resourceAccessPathSegments,
getResourcePathType(targetResourceFunc.pathSegmentSymbols), data);
resourceAccessInvocation.symbol = targetResourceFunc.symbol;
resourceAccessInvocation.targetResourceFunc = targetResourceFunc;
checkResourceAccessParamAndReturnType(resourceAccessInvocation, targetResourceFunc, data);
}

private void handleResourceAccessError(BLangListConstructorExpr resourceAccessPathSegments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public Object[][] getResourceAccessActionPathPos() {
@Test
public void testPathSegmentOfAmbiguousResourceFunction() {
Optional<Symbol> symbol = model.symbol(srcFile, LinePosition.from(91, 9));
assertTrue(symbol.isEmpty()); // Resource method is ambiguous
assertTrue(symbol.isPresent()); // Resource method is ambiguous
}

// Utils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,10 @@ public void testClientResourceCallNegative() {
"too many arguments in call to 'post()'", 90, 13);
validateError(clientResourceAccessNegative, index++,
"too many arguments in call to 'post()'", 91, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 145, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 146, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 147, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 148, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 149, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 150, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
"supported when the corresponding resource method is ambiguous", 151, 13);
validateError(clientResourceAccessNegative, index++, "client resource access action is not yet " +
Expand Down

0 comments on commit 0d1e483

Please sign in to comment.