ITADN

Type annotation without `def` fails to parse in workflow body

#7050Openpditommaso 创建于 2026-04-19
P
pditommasocommented
### Bug report A variable declaration with a type annotation but no `def` keyword fails to parse inside a `workflow` block — the parser interprets `name:` as a section label and reports a misleading error. For consistency with the other declaration forms (see matrix below), this form should be accepted. Regardless of that decision, the error message should be improved to point at the offending line and explain the actual cause. ### Reproduction ```nextflow record Sample { id: String fastq_1: Path fastq_2: Path? } def hello(sample: Sample) { println "Hello sample ${sample.id}!" } workflow { sample1: Sample = record(id: '1', fastq_1: file('1_1.fastq'), fastq_2: file('1_2.fastq')) hello(sample1) } ``` ### Error ``` Error script.nf:12:1: Invalid workflow definition -- check for missing or out-of-order section labels 12 | workflow { | ^^^^^^^^^^ 13 | sample1: Sample = record(...) ``` The error points at `workflow {` rather than the real offending line, and the message ("out-of-order section labels") does not describe the actual problem. ### Matrix tested | Form | Result | |---|---| | `sample1 = record(...)` | works | | `def sample1 = record(...)` | works | | `sample1: Sample = record(...)` | **fails** | | `def sample1: Sample = record(...)` | works | ### Expected - For consistency with the other three forms, the type-annotated form without `def` should be accepted. - In any case, the error message should point at the offending line and clearly explain the cause (e.g. "a declaration keyword is required with a type annotation" if the restriction is intentional).
1 条评论