From 0fe926fb005cd49bf1aae8987901a8fd0065e7a8 Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Sat, 25 Jan 2025 20:41:56 -0500 Subject: [PATCH] fix: use the correct type for scatter output. (#316) --- wdl-engine/CHANGELOG.md | 4 ++ wdl-engine/src/eval/v1/workflow.rs | 3 +- wdl-engine/src/value.rs | 4 ++ .../workflows/scatter-array-type/inputs.json | 1 + .../workflows/scatter-array-type/outputs.json | 6 +++ .../workflows/scatter-array-type/source.wdl | 40 +++++++++++++++++++ 6 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 wdl-engine/tests/workflows/scatter-array-type/inputs.json create mode 100644 wdl-engine/tests/workflows/scatter-array-type/outputs.json create mode 100644 wdl-engine/tests/workflows/scatter-array-type/source.wdl diff --git a/wdl-engine/CHANGELOG.md b/wdl-engine/CHANGELOG.md index b83c20690..f1e14216b 100644 --- a/wdl-engine/CHANGELOG.md +++ b/wdl-engine/CHANGELOG.md @@ -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 diff --git a/wdl-engine/src/eval/v1/workflow.rs b/wdl-engine/src/eval/v1/workflow.rs index 2c29caed3..361b511b2 100644 --- a/wdl-engine/src/eval/v1/workflow.rs +++ b/wdl-engine/src/eval/v1/workflow.rs @@ -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; @@ -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) } } diff --git a/wdl-engine/src/value.rs b/wdl-engine/src/value.rs index bf382b024..a1fadfa61 100644 --- a/wdl-engine/src/value.rs +++ b/wdl-engine/src/value.rs @@ -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)), @@ -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) -> Self { + assert!(ty.as_array().is_some()); Self { ty, elements: if elements.is_empty() { @@ -1567,6 +1569,7 @@ impl Map { ty: Type, elements: IndexMap, Value>, ) -> Self { + assert!(ty.as_map().is_some()); Self { ty, elements: if elements.is_empty() { @@ -1852,6 +1855,7 @@ impl Struct { name: Arc, members: Arc>, ) -> Self { + assert!(ty.as_struct().is_some()); Self { ty, name, members } } diff --git a/wdl-engine/tests/workflows/scatter-array-type/inputs.json b/wdl-engine/tests/workflows/scatter-array-type/inputs.json new file mode 100644 index 000000000..9e26dfeeb --- /dev/null +++ b/wdl-engine/tests/workflows/scatter-array-type/inputs.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/wdl-engine/tests/workflows/scatter-array-type/outputs.json b/wdl-engine/tests/workflows/scatter-array-type/outputs.json new file mode 100644 index 000000000..3d5c77c0a --- /dev/null +++ b/wdl-engine/tests/workflows/scatter-array-type/outputs.json @@ -0,0 +1,6 @@ +{ + "run.names": [ + "sample_one", + "sample_three" + ] +} \ No newline at end of file diff --git a/wdl-engine/tests/workflows/scatter-array-type/source.wdl b/wdl-engine/tests/workflows/scatter-array-type/source.wdl new file mode 100644 index 000000000..d6fb5b473 --- /dev/null +++ b/wdl-engine/tests/workflows/scatter-array-type/source.wdl @@ -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) + } +} \ No newline at end of file