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 13, 2023
1 parent 8dec779 commit 365d8ef
Showing 1 changed file with 16 additions and 11 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

0 comments on commit 365d8ef

Please sign in to comment.