diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java index 42f1e46b58e0..d3237f101ad7 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/CodeAnalyzer.java @@ -1510,15 +1510,15 @@ public void visit(BLangWhile whileNode, AnalyzerData data) { public void visit(BLangDo doNode, AnalyzerData data) { boolean onFailExists = doNode.onFailClause != null; boolean failureHandled = data.failureHandled; - boolean previousWithinDoBlock = data.withinDoBlock; - data.withinDoBlock = true; + boolean previousWithinDoBlock = data.withinWorkerTopLevelDo; + data.withinWorkerTopLevelDo = isCommunicationAllowedLocation(data.env) && isInWorker(data.env); if (onFailExists) { data.failureHandled = true; } analyzeNode(doNode.body, data); data.failureHandled = failureHandled; analyseOnFailClause(onFailExists, doNode.onFailClause, data); - data.withinDoBlock = previousWithinDoBlock; + data.withinWorkerTopLevelDo = previousWithinDoBlock; } @@ -2005,7 +2005,7 @@ public void visit(BLangWorkerAsyncSendExpr asyncSendExpr, AnalyzerData data) { } String workerName = asyncSendExpr.workerIdentifier.getValue(); - if (!data.withinDoBlock && (data.withinQuery || + if (!data.withinWorkerTopLevelDo && (data.withinQuery || (!isCommunicationAllowedLocation(data.env) && !data.inInternallyDefinedBlockStmt))) { this.dlog.error(asyncSendExpr.pos, DiagnosticErrorCode.UNSUPPORTED_WORKER_SEND_POSITION); was.hasErrors = true; @@ -2065,7 +2065,7 @@ public void visit(BLangWorkerSyncSendExpr syncSendExpr, AnalyzerData data) { was.hasErrors = true; } - if (!data.withinDoBlock && (data.withinQuery || + if (!data.withinWorkerTopLevelDo && (data.withinQuery || (!isCommunicationAllowedLocation(data.env) && !data.inInternallyDefinedBlockStmt))) { this.dlog.error(syncSendExpr.pos, DiagnosticErrorCode.UNSUPPORTED_WORKER_SEND_POSITION); was.hasErrors = true; @@ -4261,7 +4261,7 @@ public static class AnalyzerData { boolean loopAlterNotAllowed; // Fields related to worker system boolean inInternallyDefinedBlockStmt; - boolean withinDoBlock; + boolean withinWorkerTopLevelDo; int workerSystemMovementSequence; Stack workerActionSystemStack = new Stack<>(); Map> workerReferences = new HashMap<>();