File tree Expand file tree Collapse file tree
main/java/nextflow/script/control
test/groovy/nextflow/script/types Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5757import org .codehaus .groovy .ast .expr .ClassExpression ;
5858import org .codehaus .groovy .ast .expr .ClosureExpression ;
5959import org .codehaus .groovy .ast .expr .ConstantExpression ;
60+ import org .codehaus .groovy .ast .expr .ConstructorCallExpression ;
6061import org .codehaus .groovy .ast .expr .DeclarationExpression ;
6162import org .codehaus .groovy .ast .expr .ElvisOperatorExpression ;
6263import org .codehaus .groovy .ast .expr .EmptyExpression ;
@@ -841,6 +842,14 @@ private boolean checkTupleCall(MethodCallExpression node) {
841842 return true ;
842843 }
843844
845+ @ Override
846+ public void visitConstructorCallExpression (ConstructorCallExpression node ) {
847+ var type = node .getType ();
848+ if ( TypesEx .isRecordType (type ) )
849+ addError ("Record type " + TypesEx .getName (type ) + " cannot be used as a constructor -- use `record()` instead" , node );
850+ super .visitConstructorCallExpression (node );
851+ }
852+
844853 @ Override
845854 public void visitBinaryExpression (BinaryExpression node ) {
846855 super .visitBinaryExpression (node );
Original file line number Diff line number Diff line change @@ -1012,7 +1012,24 @@ class TypeCheckingTest extends Specification {
10121012 then :
10131013 TypesEx . getName(type) == ' String'
10141014 }
1015-
1015+
1016+ def ' should report error for record type constructor' () {
1017+ expect :
1018+ check(
1019+ ''' \
1020+ record Sample {
1021+ id: String
1022+ reads: List<Path>
1023+ }
1024+
1025+ workflow {
1026+ new Sample()
1027+ }
1028+ ''' ,
1029+ ' Record type Sample cannot be used as a constructor -- use `record()` instead'
1030+ )
1031+ }
1032+
10161033 def ' should resolve record sum' () {
10171034 when :
10181035 def exp = parseExpression(
You can’t perform that action at this time.
0 commit comments