diff --git a/modules/nf-lang/src/main/java/nextflow/script/control/VariableScopeVisitor.java b/modules/nf-lang/src/main/java/nextflow/script/control/VariableScopeVisitor.java index dcb8662d40..5136b2ab25 100644 --- a/modules/nf-lang/src/main/java/nextflow/script/control/VariableScopeVisitor.java +++ b/modules/nf-lang/src/main/java/nextflow/script/control/VariableScopeVisitor.java @@ -306,6 +306,7 @@ private void visitTypedOutputs(Statement outputs, String typeLabel) { var output = es.getExpression(); VariableExpression target; if( output instanceof VariableExpression ve ) { + visit(ve); target = ve; } else if( output instanceof AssignmentExpression assign ) { diff --git a/modules/nf-lang/src/test/groovy/nextflow/script/control/ScriptResolveTest.groovy b/modules/nf-lang/src/test/groovy/nextflow/script/control/ScriptResolveTest.groovy index a8911f0277..3171ed978a 100644 --- a/modules/nf-lang/src/test/groovy/nextflow/script/control/ScriptResolveTest.groovy +++ b/modules/nf-lang/src/test/groovy/nextflow/script/control/ScriptResolveTest.groovy @@ -182,6 +182,54 @@ class ScriptResolveTest extends Specification { errors[0].getStartLine() == 3 errors[0].getStartColumn() == 9 errors[0].getOriginalMessage() == 'Variables in a closure should be declared with `def`' + + when: + errors = check( + '''\ + workflow hello { + emit: + x + } + ''' + ) + then: + errors.size() == 1 + errors[0].getStartLine() == 3 + errors[0].getStartColumn() == 5 + errors[0].getOriginalMessage() == '`x` is not defined' + + when: + errors = check( + '''\ + workflow hello { + emit: + x = y + } + ''' + ) + then: + errors.size() == 1 + errors[0].getStartLine() == 3 + errors[0].getStartColumn() == 9 + errors[0].getOriginalMessage() == '`y` is not defined' + + when: + errors = check( + '''\ + workflow hello { + emit: + x + y + } + ''' + ) + then: + errors.size() == 2 + errors[0].getStartLine() == 3 + errors[0].getStartColumn() == 5 + errors[0].getOriginalMessage() == '`x` is not defined' + errors[1].getStartLine() == 3 + errors[1].getStartColumn() == 9 + errors[1].getOriginalMessage() == '`y` is not defined' } def 'should report an error for an undefined function' () {