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
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently when using
if ... then ... elseyou 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
resultin 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 ... elseformula<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 thedefaultsexpression proposed by #5348; however theif-thenformula proposed here would allow more complex scenarios such as chainedif elseformulas.Beta Was this translation helpful? Give feedback.
All reactions