Skip to content

Commit

Permalink
Disallow worker receive inside on-fail-clause
Browse files Browse the repository at this point in the history
  • Loading branch information
lochana-chathura committed Apr 4, 2024
1 parent 8c0be5d commit ba610e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1966,12 +1966,14 @@ private boolean isReceiveAllowedLocation(BLangFunctionBody enclInvokableBody, BL
}

private boolean isSendAllowedContext(BLangNode bLangNode) {
return isReceiveAllowedContext(bLangNode) || bLangNode.getKind() == NodeKind.IF;
return isReceiveAllowedContext(bLangNode) ||
bLangNode.getKind() == NodeKind.IF ||
bLangNode.getKind() == NodeKind.ON_FAIL;
}

private boolean isReceiveAllowedContext(BLangNode bLangNode) {
return switch (bLangNode.getKind()) {
case BLOCK_FUNCTION_BODY, BLOCK, ON_FAIL, DO_STMT -> true;
case BLOCK_FUNCTION_BODY, BLOCK, DO_STMT -> true;
default -> false;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public void testSendReceiveAllowedSyntacticPositions() {
"possible deadlocks", 74, 17);
validateError(result, index++, receiveNotAllowedError, 79, 15);
validateError(result, index++, receiveNotAllowedError, 81, 21);
validateError(result, index++, receiveNotAllowedError, 93, 13);
validateError(result, index++, receiveNotAllowedError, 94, 16);
validateError(result, index++, receiveNotAllowedError, 94, 19);
Assert.assertEquals(result.getErrorCount(), index);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ public function testReceiveAllowedLocations(boolean b) returns error? {
_ = <- function; // OK
}
} on fail {
_ = <- function; // OK
_ = <- function; // error: position not allowed
_ = <- w2|function; // error: position not allowed
}

worker w2 {
1 -> w1;
}

1 -> w1;
Expand Down

0 comments on commit ba610e5

Please sign in to comment.