Skip to content

Commit 05dccba

Browse files
committed
Report type checking errors for unsupported/legacy patterns
Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent a8d9318 commit 05dccba

3 files changed

Lines changed: 34 additions & 15 deletions

File tree

src/main/java/nextflow/script/control/TypeCheckingVisitorEx.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ private static ClassNode asDataflowType(ClassNode type, ClassNode sourceType) {
226226
public void visitProcessV2(ProcessNodeV2 node) {
227227
visitProcessDirectives(node.directives);
228228
visit(node.stagers);
229+
if( !(node.when instanceof EmptyExpression) )
230+
addError("Process `when` section is not supported with static typing -- use conditinal logic in the calling workflow instead", node.when);
229231
visit(node.when);
230232
visit(node.exec);
231233
visit(node.stub);
@@ -539,7 +541,7 @@ private void checkOperatorCall(MethodCallExpression node) {
539541

540542
var method = (MethodNode) node.getNodeMetaData(ASTNodeMarker.METHOD_TARGET);
541543
if( findAnnotation(method, Deprecated.class).isPresent() )
542-
addSoftError("Operator `" + method.getName() + "` is discouraged from use with static typing", node);
544+
addSoftError("Operator `" + method.getName() + "` is discouraged from use with static typing", node.getMethod());
543545

544546
var lhsType = elementType(receiverType);
545547
var arguments = asMethodCallArguments(node);
@@ -1199,6 +1201,12 @@ private boolean checkRecordCast(ClassNode targetType, ClassNode sourceType, ASTN
11991201
public void visitPropertyExpression(PropertyExpression node) {
12001202
super.visitPropertyExpression(node);
12011203

1204+
var mn = asMethodOutput(node);
1205+
if( mn instanceof ProcessNode || mn instanceof WorkflowNode ) {
1206+
addError("Using the `.out` property to access process/workflow outputs is not supported with static typing -- assign the output to a variable instead", node);
1207+
return;
1208+
}
1209+
12021210
var receiver = node.getObjectExpression();
12031211
var receiverType = getType(receiver);
12041212
if( ClassHelper.isDynamicTyped(receiverType) )
@@ -1217,15 +1225,8 @@ public void visitPropertyExpression(PropertyExpression node) {
12171225
return;
12181226
}
12191227

1220-
var mn = asMethodNamedOutput(node);
12211228
var property = node.getPropertyAsString();
1222-
if( mn instanceof ProcessNode pn ) {
1223-
addError("Unrecognized output `" + property + "` for process `" + pn.getName() + "`", node);
1224-
}
1225-
else if( mn instanceof WorkflowNode wn ) {
1226-
addError("Unrecognized output `" + property + "` for workflow `" + wn.getName() + "`", node);
1227-
}
1228-
else if( TypesEx.isEqual(receiverType, PARAMS_TYPE) ) {
1229+
if( TypesEx.isEqual(receiverType, PARAMS_TYPE) ) {
12291230
if( hasParamsBlock )
12301231
addError("Unrecognized parameter `" + property + "`", node);
12311232
}
@@ -1274,12 +1275,6 @@ private void checkSpreadProperty(PropertyExpression node) {
12741275
}
12751276
}
12761277

1277-
private static MethodNode asMethodNamedOutput(PropertyExpression node) {
1278-
if( node.getObjectExpression() instanceof PropertyExpression pe )
1279-
return asMethodOutput(pe);
1280-
return null;
1281-
}
1282-
12831278
public void addWarning(String message, String tokenText, ASTNode node) {
12841279
var token = new Token(0, tokenText, node.getLineNumber(), node.getColumnNumber()); // ASTNode to CSTNode
12851280
sourceUnit.getErrorCollector().addWarning(WarningMessage.POSSIBLE_ERRORS, message, token, sourceUnit);

src/main/java/nextflow/script/types/TypeCheckingUtils.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ public static MethodNode asDummyMethod(ClassNode receiverType, MethodNode method
472472
ClassNode.EMPTY_ARRAY,
473473
method.getCode() );
474474
result.setDeclaringClass(receiverType != null ? receiverType : method.getDeclaringClass());
475+
result.addAnnotations(method.getAnnotations());
475476
return result;
476477
}
477478

src/test/groovy/nextflow/script/types/TypeCheckingTest.groovy

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,29 @@ class TypeCheckingTest extends Specification {
924924
TypesEx.getName(type) == 'Value<Record {\n target: String\n message: String\n}>'
925925
}
926926

927+
def 'should report error for process .out property' () {
928+
expect:
929+
check(
930+
'''
931+
nextflow.preview.types = true
932+
933+
process hello {
934+
output:
935+
stdout()
936+
937+
script:
938+
''
939+
}
940+
941+
workflow {
942+
hello()
943+
hello.out
944+
}
945+
''',
946+
'Using the `.out` property to access process/workflow outputs is not supported with static typing -- assign the output to a variable instead'
947+
)
948+
}
949+
927950
def 'should resolve record type' () {
928951
when:
929952
def exp = parseExpression(

0 commit comments

Comments
 (0)