codeql-cli-binaries icon indicating copy to clipboard operation
codeql-cli-binaries copied to clipboard

Suggestion: `boolean(<formula>)` expression

Open Marcono1234 opened this issue 4 years ago • 1 comments

Especially when debugging queries it can often be interesting to know whether a predicate (or a relation) holds or not. However, you can only use expressions in result sets, requiring you to manually get a boolean value for the predicate in question, e.g.:

import java

from Method m, boolean isStatic
where
  if m.isStatic() then isStatic = true
  else isStatic = false
select m, isStatic

Therefore it might be useful to introduce a boolean(<formula>) expression. If the formula holds, then the result is true, otherwise false:

import java

from Method m
select m, boolean(m.isStatic())

Marcono1234 avatar Mar 24 '21 22:03 Marcono1234

Thanks for the suggestion; I've wanted this myself a few times. I've handed this over to the product team to consider for a future update.

dbartol avatar Mar 26 '21 14:03 dbartol