Skip to content

Commit a970714

Browse files
committed
Fix params inclusion across modules in v2 parser (#6766)
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 701c82c commit a970714

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

modules/nextflow/src/test/groovy/nextflow/script/ScriptIncludesTest.groovy

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,4 +1190,32 @@ class ScriptIncludesTest extends Dsl2Spec {
11901190
then:
11911191
result == 'dlrow olleH'
11921192
}
1193+
1194+
def 'should load current params in included module' () {
1195+
given:
1196+
def folder = Files.createTempDirectory('test')
1197+
1198+
folder.resolve('main.nf').text = '''
1199+
params.outdir = "results"
1200+
1201+
include { echoParams } from './module.nf'
1202+
1203+
return echoParams()
1204+
'''
1205+
1206+
folder.resolve('module.nf').text = '''
1207+
def echoParams() {
1208+
return params
1209+
}
1210+
'''
1211+
1212+
when:
1213+
def runner = new MockScriptRunner()
1214+
def result = runner.setScript(folder.resolve('main.nf')).execute()
1215+
then:
1216+
result == [outdir: 'results']
1217+
1218+
cleanup:
1219+
folder?.deleteDir()
1220+
}
11931221
}

modules/nf-lang/src/main/java/nextflow/script/control/ScriptToGroovyVisitor.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package nextflow.script.control;
1717

1818
import java.util.Arrays;
19+
import java.util.Comparator;
1920
import java.util.List;
2021
import java.util.Set;
2122
import java.util.stream.Collectors;
@@ -28,6 +29,7 @@
2829
import nextflow.script.ast.OutputBlockNode;
2930
import nextflow.script.ast.ParamBlockNode;
3031
import nextflow.script.ast.ParamNodeV1;
32+
import nextflow.script.ast.ProcessNode;
3133
import nextflow.script.ast.ProcessNodeV1;
3234
import nextflow.script.ast.ProcessNodeV2;
3335
import nextflow.script.ast.ScriptNode;
@@ -84,7 +86,30 @@ protected SourceUnit getSourceUnit() {
8486
public void visit() {
8587
if( moduleNode == null )
8688
return;
87-
super.visit(moduleNode);
89+
90+
var declarations = moduleNode.getDeclarations();
91+
92+
declarations.sort(Comparator.comparing(node -> node.getLineNumber()));
93+
94+
for( var decl : declarations ) {
95+
if( decl instanceof FeatureFlagNode ffn )
96+
visitFeatureFlag(ffn);
97+
else if( decl instanceof FunctionNode fn )
98+
visitFunction(fn);
99+
else if( decl instanceof IncludeNode in )
100+
visitInclude(in);
101+
else if( decl instanceof OutputBlockNode obn )
102+
visitOutputs(obn);
103+
else if( decl instanceof ParamBlockNode pbn )
104+
visitParams(pbn);
105+
else if( decl instanceof ParamNodeV1 pn )
106+
visitParamV1(pn);
107+
else if( decl instanceof ProcessNode pn )
108+
visitProcess(pn);
109+
else if( decl instanceof WorkflowNode wn )
110+
visitWorkflow(wn);
111+
}
112+
88113
if( moduleNode.isEmpty() )
89114
moduleNode.addStatement(ReturnStatement.RETURN_NULL_OR_VOID);
90115
}

0 commit comments

Comments
 (0)