CodeQL: Add if
which binds variables in 'then'
#5573
Marcono1234
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently when using
if ... then ... else
you often have to repeat code in the condition formula and in the then formula. This can be rather verbose and error-prone, e.g.:Trying to bind
result
in the condition formula would not work, because when the result is then also restricted somewhere else instead of having no result it would simply evaluate the else formula.This could possibly be solved by introducing an if-then formula (feedback appreciated):
if-then(<variable-declarations> | <condition-formula> | <then-formula>) else <else-formula>
<variable-declarations>
: One or more variable declarations; zero declarations would probably make no sense since it would then be the same as a regularif ... then ... else
formula<condition-formula>
: If this formula holds, the<then-formula>
is evaluated, otherwise the<else-formula>
is evaluatedExample:
Note that simple cases such as
if ... then result = ... else result = ...
could be solved using thedefaults
expression proposed by #5348; however theif-then
formula proposed here would allow more complex scenarios such as chainedif else
formulas.Beta Was this translation helpful? Give feedback.
All reactions