diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java index 53fb819705dd..40fbad6c0f37 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/TypeChecker.java @@ -3823,10 +3823,9 @@ 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; } @@ -3834,14 +3833,12 @@ public void visit(BLangInvocation.BLangResourceAccessInvocation resourceAccessIn 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, @@ -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 pathSegmentSymbols) { BType restType = null; int pathSegmentCount = pathSegmentSymbols.size(); diff --git a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json index 2f3801fcc192..c8d1489e7524 100644 --- a/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json +++ b/language-server/modules/langserver-core/src/test/resources/completion/action_node_context/config/client_resource_access_action_config44.json @@ -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",