Skip to content

Commit

Permalink
Add common method for resource access error
Browse files Browse the repository at this point in the history
  • Loading branch information
nipunayf committed Nov 20, 2023
1 parent 0ddaa55 commit a2f69d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3823,25 +3823,22 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn
}

if (resourceFunctions.size() == 0) {
checkExpr(resourceAccessInvocation.resourceAccessPathSegments, data);
dlog.error(resourceAccessInvocation.resourceAccessPathSegments.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE,
lhsExprType);
data.resultType = symTable.semanticError;
handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments,
resourceAccessInvocation.resourceAccessPathSegments.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE,
data, lhsExprType);
return;
}

// Filter the resource methods in the list by resource access method name
resourceFunctions.removeIf(func -> !func.accessor.value.equals(resourceAccessInvocation.name.value));
int targetResourceFuncCount = resourceFunctions.size();
if (targetResourceFuncCount == 0) {
checkExpr(resourceAccessInvocation.resourceAccessPathSegments, data);
dlog.error(resourceAccessInvocation.name.pos,
DiagnosticErrorCode.UNDEFINED_RESOURCE_METHOD, resourceAccessInvocation.name, lhsExprType);
data.resultType = symTable.semanticError;
handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments,
resourceAccessInvocation.name.pos, DiagnosticErrorCode.UNDEFINED_RESOURCE_METHOD, data,
resourceAccessInvocation.name, lhsExprType);
} else if (targetResourceFuncCount > 1) {
checkExpr(resourceAccessInvocation.resourceAccessPathSegments, data);
dlog.error(resourceAccessInvocation.pos, DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED);
data.resultType = symTable.semanticError;
handleResourceAccessError(resourceAccessInvocation.resourceAccessPathSegments, resourceAccessInvocation.pos,
DiagnosticErrorCode.AMBIGUOUS_RESOURCE_ACCESS_NOT_YET_SUPPORTED, data, lhsExprType);
} else {
BResourceFunction targetResourceFunc = resourceFunctions.get(0);
checkExpr(resourceAccessInvocation.resourceAccessPathSegments,
Expand All @@ -3852,6 +3849,14 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn
}
}

private void handleResourceAccessError(BLangListConstructorExpr resourceAccessPathSegments,
Location diagnosticLocation, DiagnosticErrorCode errorCode,
AnalyzerData data, Object... dlogArgs) {
checkExpr(resourceAccessPathSegments, data);
dlog.error(diagnosticLocation, errorCode, dlogArgs);
data.resultType = symTable.semanticError;
}

private BTupleType getResourcePathType(List<BResourcePathSegmentSymbol> pathSegmentSymbols) {
BType restType = null;
int pathSegmentCount = pathSegmentSymbols.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"character": 25
},
"source": "action_node_context/source/client_resource_access_action_source37.bal",
"description": "",
"description": "Test completions after a variable resource path",
"items": [
{
"label": "/third",
Expand Down

0 comments on commit a2f69d7

Please sign in to comment.