Skip to content

[BUG] ternary executes the function disregarding of the condition result #1133

Description

@Tirito6626

Describe the bug
any ternary expression will execute the function on either result of the condition if the true or false part includes a function

To Reproduce

fun test(): Text {
   echo("executed")
   return "bar"
}
main (args) {
  echo(
    len(args) >= 1 then "foo" else test() // always true, to show that the function is function is executed either way
   )
}

returns:

executed
foo

Expected behavior

foo

Additional context
the issue is caused by src/modules/function/invocation.rs automatically pushing the function execution back into query during translation in src/expression/ternop/ternary.rs, where only the return variable is then generated

test__0_v0 
ret_test0_v0__7_27="${ret_test0_v0}"
printf '%s\n' "$(if (( 2 > 1 )); then echo "foo"; else echo "${ret_test0_v0__7_27}"; fi)"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingcompiler

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions