Skip to content

Commit 236af6f

Browse files
authored
Clarify parameter reference: null and array length (#64)
* Address ambiguity on null and inputs.somearray.length in parameter reference * Clarify that the length field can sometimes apply to a non-array input
1 parent 8615de9 commit 236af6f

6 files changed

+111
-10
lines changed

concepts.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,23 @@ or more repeats, and all other characters are literal values.
510510
Use the following algorithm to resolve a parameter reference:
511511

512512
1. Match the leading symbol as the key
513-
2. Look up the key in the parameter context (described below) to get the current value.
513+
2. If the key is the special value 'null' then the
514+
value of the parameter reference is 'null'. If the key is 'null' it must be the only symbol in the parameter reference.
515+
3. Look up the key in the parameter context (described below) to get the current value.
514516
It is an error if the key is not found in the parameter context.
515-
3. If there are no subsequent segments, terminate and return current value
516-
4. Else, match the next segment
517-
5. Extract the symbol, string, or index from the segment as the key
518-
6. Look up the key in current value and assign as new current value. If
519-
the key is a symbol or string, the current value must be an object.
520-
If the key is an index, the current value must be an array or string.
521-
It is an error if the key does not match the required type, or the key is not found or out
522-
of range.
523-
7. Repeat steps 3-6
517+
4. If there are no subsequent segments, terminate and return current value
518+
5. Else, match the next segment
519+
6. Extract the symbol, string, or index from the segment as the key
520+
7. Look up the key in current value and assign as new current value.
521+
1. If the key is a symbol or string, the current value must be an object.
522+
2. If the key is an index, the current value must be an array or string.
523+
3. If the next key is the last key and it has the special value 'length' and
524+
the current value is an array, the value of the parameter reference is the
525+
length of the array. If the value 'length' is encountered in other contexts, normal
526+
evaluation rules apply.
527+
4. It is an error if the key does not match the required type, or the key is not found or out
528+
of range.
529+
8. Repeat steps 3-8
524530

525531
The root namespace is the parameter context. The following parameters must
526532
be provided:

conformance_tests.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,3 +3399,25 @@
33993399
- $import: tests/mixed-versions/test-index.yaml
34003400
- $import: tests/loadContents/test-index.yaml
34013401
- $import: tests/iwd/test-index.yaml
3402+
3403+
- job: tests/empty.json
3404+
tool: tests/params_broken_null.cwl
3405+
label: params_broken_null
3406+
doc: Test parameter reference that refers to null.something
3407+
should_fail: true
3408+
tags: [ required, command_line_tool ]
3409+
3410+
- job: tests/empty.json
3411+
tool: tests/params_broken_length_of_non_list.cwl
3412+
doc: Test paramer reference that refers to length of non-array input
3413+
should_fail: true
3414+
tags: [ required, command_line_tool ]
3415+
3416+
- job: tests/length_non_array_input.yml
3417+
tool: tests/params_input_length_non_array.cwl
3418+
doc: Test 'length' in parameter reference where it does not refer to length of an array input
3419+
tags: [ required, command_line_tool ]
3420+
output:
3421+
output1: 1
3422+
output2: 2
3423+
output3: 3

tests/length_non_array_input.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bar:
2+
length: 2
3+
baz:
4+
length:
5+
bap: 3
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.2
3+
inputs:
4+
bar:
5+
type: Any
6+
default: 0
7+
8+
outputs:
9+
output1:
10+
type: Any
11+
outputBinding:
12+
outputEval: $(inputs.bar.length)
13+
14+
baseCommand: "true"

tests/params_broken_null.cwl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.2
3+
inputs:
4+
bar:
5+
type: Any
6+
default: "something"
7+
8+
outputs:
9+
output1:
10+
type: "null"
11+
outputBinding:
12+
outputEval: $(null.something)
13+
14+
baseCommand: "true"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class: CommandLineTool
2+
cwlVersion: v1.2
3+
inputs:
4+
length:
5+
type: int
6+
default: 1
7+
bar:
8+
type:
9+
type: record
10+
name: bar_record
11+
fields:
12+
length:
13+
type: int
14+
baz:
15+
type:
16+
type: record
17+
name: baz_record
18+
fields:
19+
length:
20+
type:
21+
type: record
22+
name: length_record
23+
fields:
24+
bap:
25+
type: int
26+
27+
outputs:
28+
output1:
29+
type: int
30+
outputBinding:
31+
outputEval: $(inputs.length)
32+
output2:
33+
type: int
34+
outputBinding:
35+
outputEval: $(inputs.bar.length)
36+
output3:
37+
type: int
38+
outputBinding:
39+
outputEval: $(inputs.baz.length.bap)
40+
baseCommand: "true"

0 commit comments

Comments
 (0)