Skip to content

Commit

Permalink
fix: use the correct type for scatter output. (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterhuene authored Jan 26, 2025
1 parent 896981f commit 0fe926f
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions wdl-engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

* Added progress callback to `WorkflowEvaluator` ([#310](https://github.com/stjude-rust-labs/wdl/pull/310)).

### Fixed

* Fixed an incorrect type being used for scatter statement outputs ([#316](https://github.com/stjude-rust-labs/wdl/pull/316)).

## 0.1.0 - 01-17-2025

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion wdl-engine/src/eval/v1/workflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use wdl_analysis::document::Task;
use wdl_analysis::document::Workflow;
use wdl_analysis::eval::v1::WorkflowGraphBuilder;
use wdl_analysis::eval::v1::WorkflowGraphNode;
use wdl_analysis::types::ArrayType;
use wdl_analysis::types::CallType;
use wdl_analysis::types::Optional;
use wdl_analysis::types::PrimitiveType;
Expand Down Expand Up @@ -287,7 +288,7 @@ impl GatherArray {

/// Converts the gather array into a WDL array value.
fn into_array(self) -> Array {
Array::new_unchecked(self.element_ty, self.elements)
Array::new_unchecked(ArrayType::new(self.element_ty).into(), self.elements)
}
}

Expand Down
4 changes: 4 additions & 0 deletions wdl-engine/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,7 @@ impl Pair {
/// Constructs a new pair without checking the given left and right conform
/// to the given type.
pub(crate) fn new_unchecked(ty: Type, left: Value, right: Value) -> Self {
assert!(ty.as_pair().is_some());
Self {
ty,
values: Arc::new((left, right)),
Expand Down Expand Up @@ -1441,6 +1442,7 @@ impl Array {
/// Constructs a new array without checking the given elements conform to
/// the given type.
pub(crate) fn new_unchecked(ty: Type, elements: Vec<Value>) -> Self {
assert!(ty.as_array().is_some());
Self {
ty,
elements: if elements.is_empty() {
Expand Down Expand Up @@ -1567,6 +1569,7 @@ impl Map {
ty: Type,
elements: IndexMap<Option<PrimitiveValue>, Value>,
) -> Self {
assert!(ty.as_map().is_some());
Self {
ty,
elements: if elements.is_empty() {
Expand Down Expand Up @@ -1852,6 +1855,7 @@ impl Struct {
name: Arc<String>,
members: Arc<IndexMap<String, Value>>,
) -> Self {
assert!(ty.as_struct().is_some());
Self { ty, name, members }
}

Expand Down
1 change: 1 addition & 0 deletions wdl-engine/tests/workflows/scatter-array-type/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
6 changes: 6 additions & 0 deletions wdl-engine/tests/workflows/scatter-array-type/outputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"run.names": [
"sample_one",
"sample_three"
]
}
40 changes: 40 additions & 0 deletions wdl-engine/tests/workflows/scatter-array-type/source.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## This is a test for https://github.com/stjude-rust-labs/wdl/issues/315
## This test will output an array rather than emit a diagnostic
version 1.2

struct Sample {
String kind
String name
}

workflow run {
Array[Sample] samples = [
Sample {
kind: "normal",
name: "sample_one",
},
Sample {
kind: "tumor",
name: "sample_two",
},
Sample {
kind: "normal",
name: "sample_three",
},
Sample {
kind: "tumor",
name: "sample_four",
},
]

scatter (sample in samples) {
if (sample.kind == "normal") {
String name = sample.name
}
}

output {
Array[String] names = select_all(name)
}
}

0 comments on commit 0fe926f

Please sign in to comment.