Skip to content

Commit f062065

Browse files
authored
Fix bug in generated Groovy code (#6082)
--------- Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 8f79061 commit f062065

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

modules/nextflow/src/main/groovy/nextflow/script/parser/v2/ScriptLoaderV2.groovy

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,20 +115,25 @@ class ScriptLoaderV2 implements ScriptLoader {
115115
})
116116
}
117117
catch( CompilationFailedException e ) {
118-
final errorListener = new StandardErrorListener('full', false)
119-
println()
120-
errorListener.beforeErrors()
121-
for( final message : compiler.getErrors() ) {
122-
final cause = message.getCause()
123-
final source = getSource(cause.getSourceLocator(), compiler)
124-
final filename = getRelativePath(source, scriptPath)
125-
errorListener.onError(cause, filename, source)
126-
}
127-
errorListener.afterErrors()
118+
if( scriptPath )
119+
printErrors(scriptPath)
128120
throw new ScriptCompilationException("Script compilation failed", e)
129121
}
130122
}
131123

124+
private void printErrors(Path path) {
125+
final errorListener = new StandardErrorListener('full', false)
126+
println()
127+
errorListener.beforeErrors()
128+
for( final message : compiler.getErrors() ) {
129+
final cause = message.getCause()
130+
final source = getSource(cause.getSourceLocator(), compiler)
131+
final filename = getRelativePath(source, path)
132+
errorListener.onError(cause, filename, source)
133+
}
134+
errorListener.afterErrors()
135+
}
136+
132137
private SourceUnit getSource(String sourceLocator, ScriptCompiler compiler) {
133138
for( final su : compiler.getSources() ) {
134139
if( sourceLocator == su.getName() )

modules/nextflow/src/test/groovy/nextflow/script/parser/v2/ScriptLoaderV2Test.groovy

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,40 @@ class ScriptLoaderV2Test extends Specification {
8383
cleanup:
8484
file.parent.deleteDir()
8585
}
86-
86+
87+
def 'should register workflow definition' () {
88+
89+
given:
90+
def session = new Session()
91+
def parser = new ScriptLoaderV2(session)
92+
93+
def TEXT = '''
94+
95+
workflow hello {
96+
take:
97+
foo ; bar
98+
99+
main:
100+
def foobar = foo + bar
101+
102+
emit:
103+
result = foobar
104+
}
105+
106+
workflow {
107+
hello('foo', 'bar')
108+
}
109+
'''
110+
111+
when:
112+
parser.parse(TEXT)
113+
parser.runScript()
114+
def meta = ScriptMeta.get(parser.getScript())
115+
116+
then:
117+
meta.definitions.size() == 2
118+
meta.getWorkflow('hello').declaredInputs == ['foo', 'bar']
119+
meta.getWorkflow('hello').declaredOutputs == ['result']
120+
}
121+
87122
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ private void visitWorkflowEmits(Statement emits, Statement main) {
167167
}
168168
else if( emit instanceof AssignmentExpression ae ) {
169169
var target = (VariableExpression)ae.getLeftExpression();
170+
code.addStatement(assignS(target, emit));
170171
es.setExpression(callThisX("_emit_", args(constX(target.getName()))));
171172
code.addStatement(es);
172173
}

0 commit comments

Comments
 (0)