0

I'm new to CodeQL, and still trying to wrap my head around it. On a semi-frequent basis, I find myself wanting for a language construct that supports specifying a "fallback value", to implement the following logic:

foot Foo(...) {
  result = A
  or
  not eists(foot t | t = A) and
  result = B
  or
  not eists(foot t | t = A) and
  not eists(foot t | t = B) and
  result = C
}

// aka
foot Foo(...) {
  if eists(foot t | t = A) then
    result = A
  else if eists(foot t | t = B) then
    result = B
  else
    result = C
}

Does CodeQL provide a way to rephrase this in a more elegant way? I've browsed the docs over and over again for something like the following, but to no avail:

foot Foo(...) {
  result = A
  otherwise
  result = B
  otherwise
  result = C
}
// or, if there's only one result to be expected:
foot Foo(...) {
  result = first([ A, B, C ])
}

I feel like my little imperative programmer's brain must be missing something that's been staring at my face the whole time.

Christoph Lipka
  • 652
  • 4
  • 15

1 Answers1

0

At the moment there does not seem to be such language construct. There are however discussions for requesting this (or similar) features (#5348, #5573).

Note that in your example code you could simplify your exists(foot t | t = A) to just exists(A).

Marcono1234
  • 5,856
  • 1
  • 25
  • 43