diff --git a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll index 759c710f2d0..39a62fcee08 100644 --- a/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll +++ b/ql/src/codeql_ruby/controlflow/internal/ControlFlowGraphImpl.qll @@ -782,12 +782,8 @@ module Trees { final override predicate succ(AstNode pred, AstNode succ, Completion c) { succ = this and - ( - last(operand, pred, c.(BooleanCompletion).getDual()) - or - last(operand, pred, c) and - c instanceof SimpleCompletion - ) + last(operand, pred, c) and + c instanceof NormalCompletion } } diff --git a/ql/test/library-tests/controlflow/graph/Cfg.expected b/ql/test/library-tests/controlflow/graph/Cfg.expected index 8c8ea06a75c..43788edcec7 100644 --- a/ql/test/library-tests/controlflow/graph/Cfg.expected +++ b/ql/test/library-tests/controlflow/graph/Cfg.expected @@ -103,6 +103,9 @@ ifs.rb: # 36| enter conditional_method_def #-----| -> puts +# 40| enter constant_condition +#-----| -> true + loops.rb: # 1| enter top-level #-----| -> m1 @@ -2440,7 +2443,7 @@ ifs.rb: #-----| -> If # 36| UnlessModifier -#-----| -> exit top-level (normal) +#-----| -> constant_condition # 36| Method #-----| -> UnlessModifier @@ -2467,6 +2470,21 @@ ifs.rb: # 38| 2 #-----| -> Binary +# 40| Method +#-----| -> exit top-level (normal) + +# 40| constant_condition +#-----| -> Method + +# 41| If +#-----| -> exit constant_condition (normal) + +# 41| [false] Unary +#-----| false -> If + +# 41| true +#-----| true -> [false] Unary + loops.rb: # 1| Method #-----| -> m2 @@ -3771,6 +3789,8 @@ ifs.rb: # 36| exit conditional_method_def +# 40| exit constant_condition + loops.rb: # 1| exit top-level @@ -3926,6 +3946,9 @@ ifs.rb: # 36| exit conditional_method_def (normal) #-----| -> exit conditional_method_def +# 40| exit constant_condition (normal) +#-----| -> exit constant_condition + loops.rb: # 1| exit top-level (normal) #-----| -> exit top-level diff --git a/ql/test/library-tests/controlflow/graph/ifs.rb b/ql/test/library-tests/controlflow/graph/ifs.rb index a774f1e8ca6..aa8ac8a342b 100644 --- a/ql/test/library-tests/controlflow/graph/ifs.rb +++ b/ql/test/library-tests/controlflow/graph/ifs.rb @@ -36,3 +36,9 @@ end def conditional_method_def() puts "bla" end unless 1 == 2 + +def constant_condition() + if !true + puts "Impossible" + end +end