Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if...then...else type checks in command blocks #318

Open
adthrasher opened this issue Jan 29, 2025 · 3 comments
Open

if...then...else type checks in command blocks #318

adthrasher opened this issue Jan 29, 2025 · 3 comments

Comments

@adthrasher
Copy link
Member

In the workflow repo, we have a block of WDL code in a command block like this:

            --clip3pAdapterMMp ~{clip_3p_adapter_mmp.left} ~{(
                if (length(read_two_fastqs_gz) != 0)
                then "~{clip_3p_adapter_mmp.right}"
                else ""
            )} \

Stylistically, we want to drop the "~{}" wrapper from the then arm of the conditional. However, sprocket warns that the then and else arms return different types (float and string), specifically type mismatch: expected type Float, but found type String``. Since there is no further expression and the result of this conditional is returned into the command block which is interpolated to `string`, is this a check that could be relaxed?

@claymcleod
Copy link
Member

Provided it is easy to implement, it seems like a good thing to do. WDL tends to treat types that can be coerced as more of an implicit action anyway, so it feels in line with what the intention is there.

@peterhuene
Copy link
Collaborator

peterhuene commented Jan 29, 2025

I don't think this can be changed as the if expression should statically produce a single type, otherwise static analysis would have to always treat the type of the expression as Union (i.e. it produces any type).

Static analysis should not treat the type production of an expression differently depending on where the expression is encountered in the AST, either.

If you want to remove the nested interpolation, how about this expression instead?

~{
    if (length(read_two_fastqs_gz) != 0)
    then clip_3p_adapter_mmp.right
    else None
}

The type of this expression is Float?, which will interpolate to an empty string if None (when read_two_fastqs_gz is length 0).

@peterhuene
Copy link
Collaborator

peterhuene commented Jan 29, 2025

FWIW, miniwdl appears to incorrectly accept an if expression with different branch types as it plays pretty loose with WDL's static type system (e.g. String foo = 1 is accepted by miniwdl).

Here's the relevant part of the spec:

The if-true and if-false expressions must return values of the same type, such that the value of the if-then-else is the same regardless of which side is evaluated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants