Skip to content

Commit

Permalink
Eliminate some false positive warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
  • Loading branch information
bentsherman committed Dec 12, 2024
1 parent 88ca490 commit 5bc416e
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ private boolean declareAssignedVariable(VariableExpression ve) {
if( isBuiltinVariable(variable) )
addError("Built-in variable cannot be re-assigned", ve);
else
checkExternalWriteInClosure(ve, variable);
checkExternalWriteInAsyncClosure(ve, variable);
ve.setAccessedVariable(variable);
return false;
}
Expand Down Expand Up @@ -546,17 +546,20 @@ else if( node instanceof BinaryExpression be && be.getOperation().getType() == T
// addError("Built-in variable cannot be mutated", target);
}
else if( variable != null ) {
checkExternalWriteInClosure(target, variable);
checkExternalWriteInAsyncClosure(target, variable);
}
}

private void checkExternalWriteInClosure(VariableExpression target, Variable variable) {
private void checkExternalWriteInAsyncClosure(VariableExpression target, Variable variable) {
if( !(currentDefinition instanceof WorkflowNode) )
return;
if( currentClosure == null )
return;
var scope = currentClosure.getVariableScope();
var name = variable.getName();
// TODO: should apply only to operator closures
if( scope.isReferencedLocalVariable(name) && scope.getDeclaredVariable(name) == null )
addFutureWarning("Mutating an external variable in a closure may lead to a race condition", target, "External variable declared here", (ASTNode) variable);
addFutureWarning("Mutating an external variable in an operator closure may lead to a race condition", target, "External variable declared here", (ASTNode) variable);
}

/**
Expand Down Expand Up @@ -641,7 +644,7 @@ public void visitVariableExpression(VariableExpression node) {
Variable variable = findVariableDeclaration(name, node);
if( variable == null ) {
if( "it".equals(name) ) {
addFutureWarning("Implicit variable `it` in closure will not be supported in a future version", node);
addFutureWarning("Implicit closure parameter `it` will not be supported in a future version", node);
}
else if( "args".equals(name) ) {
addFutureWarning("The use of `args` outside the entry workflow will not be supported in a future version", node);
Expand Down

0 comments on commit 5bc416e

Please sign in to comment.