Skip to content

Commit

Permalink
Fix detection of built-in variables
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
  • Loading branch information
bentsherman committed Nov 21, 2024
1 parent b8e7f50 commit c81e242
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ else if( node instanceof VariableExpression ve ) {
private void declareAssignedVariable(VariableExpression ve) {
var variable = findVariableDeclaration(ve.getName(), ve);
if( variable != null ) {
if( variable instanceof PropertyNode pn && pn.getNodeMetaData("access.method") != null )
if( isBuiltinVariable(variable) )
addError("Built-in variable cannot be re-assigned", ve);
else
checkExternalWriteInClosure(ve, variable);
Expand All @@ -530,6 +530,12 @@ else if( currentDefinition instanceof ProcessNode || currentDefinition instanceo
}
}

private boolean isBuiltinVariable(Variable variable) {
return variable instanceof PropertyNode pn
&& pn.getNodeMetaData("access.method") instanceof MethodNode mn
&& findAnnotation(mn, Constant.class).isPresent();
}

private void visitMutatedVariable(Expression node) {
VariableExpression target = null;
while( true ) {
Expand All @@ -550,7 +556,7 @@ else if( node instanceof BinaryExpression be && be.getOperation().getType() == T
if( target == null )
return;
var variable = findVariableDeclaration(target.getName(), target);
if( variable instanceof PropertyNode pn && pn.getNodeMetaData("access.method") != null ) {
if( isBuiltinVariable(variable) ) {
if( "params".equals(variable.getName()) )
sourceUnit.addWarning("Params should be declared at the top-level (i.e. outside the workflow)", target);
// TODO: re-enable after workflow.onComplete bug is fixed
Expand Down

0 comments on commit c81e242

Please sign in to comment.