Skip to content

Check for duplicate process/workflow calls in strict syntax #6324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
package nextflow.script.control;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import nextflow.script.ast.ASTNodeMarker;
import nextflow.script.ast.AssignmentExpression;
Expand Down Expand Up @@ -168,12 +170,15 @@ public void visitFeatureFlag(FeatureFlagNode node) {
}
}

private Set<String> workflowComponents;

private boolean inWorkflowEmit;

@Override
public void visitWorkflow(WorkflowNode node) {
vsc.pushScope(node.isEntry() ? EntryWorkflowDsl.class : WorkflowDsl.class);
currentDefinition = node;
workflowComponents = new HashSet<String>();
node.setVariableScope(currentScope());

declareWorkflowInputs(node.takes);
Expand All @@ -185,6 +190,7 @@ public void visitWorkflow(WorkflowNode node) {
visitWorkflowOutputs(node.emits, "emit");
visitWorkflowOutputs(node.publishers, "output");

workflowComponents = null;
currentDefinition = null;
vsc.popScope();
}
Expand Down Expand Up @@ -590,6 +596,14 @@ private void checkDataflowMethod(MethodCallExpression node, MethodNode mn) {
vsc.addError(type + " cannot be called from within a closure", node);
return;
}
if( mn instanceof ProcessNode || mn instanceof WorkflowNode ) {
var name = node.getMethodAsString();
if( workflowComponents.contains(name) ) {
var type = mn instanceof ProcessNode ? "Process" : "Workflow";
vsc.addError(type + " `" + name + "` cannot be called more than once in the same workflow -- use an alias instead", node);
}
workflowComponents.add(name);
}
}

private static String dataflowMethodType(MethodNode mn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,28 @@ class ScriptResolveTest extends Specification {
errors[0].getStartLine() == 10
errors[0].getStartColumn() == 9
errors[0].getOriginalMessage() == 'Processes cannot be called from within a closure'

when:
errors = check(
'''\
process hello {
script:
"""
echo hello
"""
}

workflow {
hello()
hello()
}
'''
)
then:
errors.size() == 1
errors[0].getStartLine() == 10
errors[0].getStartColumn() == 5
errors[0].getOriginalMessage() == 'Process `hello` cannot be called more than once in the same workflow -- use an alias instead'
}

def 'should report an error for an invalid workflow invocation' () {
Expand Down Expand Up @@ -294,6 +316,24 @@ class ScriptResolveTest extends Specification {
errors[0].getStartLine() == 6
errors[0].getStartColumn() == 9
errors[0].getOriginalMessage() == 'Workflows cannot be called from within a closure'

when:
errors = check(
'''\
workflow hello {
}

workflow {
hello()
hello()
}
'''
)
then:
errors.size() == 1
errors[0].getStartLine() == 6
errors[0].getStartColumn() == 5
errors[0].getOriginalMessage() == 'Workflow `hello` cannot be called more than once in the same workflow -- use an alias instead'
}

}