Skip to content

Commit 660e52f

Browse files
committed
Ruby: CFG: make VariableReferencePattern a PreOrder node
1 parent e9e3ef3 commit 660e52f

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

ruby/ql/lib/codeql/ruby/controlflow/internal/Completion.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ private predicate inMatchingContext(AstNode n) {
227227
or
228228
n instanceof CasePattern
229229
or
230+
n = any(VariableReferencePattern p).getVariableAccess()
231+
or
230232
n = any(CasePattern c).getDesugared()
231233
or
232234
n.(Trees::DefaultValueParameterTree).hasDefaultValue()

ruby/ql/lib/codeql/ruby/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ module Trees {
722722
override ControlFlowTree getChildElement(int i) { result = this.getPattern() and i = 0 }
723723
}
724724

725-
private class VariableReferencePatternTree extends StandardPostOrderTree, VariableReferencePattern {
725+
private class VariableReferencePatternTree extends StandardPreOrderTree, VariableReferencePattern {
726726
override ControlFlowTree getChildElement(int i) { result = this.getVariableAccess() and i = 0 }
727727
}
728728

ruby/ql/test/library-tests/controlflow/graph/Cfg.expected

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,14 +1046,14 @@ case.rb:
10461046
#-----| match -> exit case_match_various (normal)
10471047

10481048
# 74| in ... then ...
1049-
#-----| -> foo
1049+
#-----| -> ^...
10501050

10511051
# 74| ^...
1052-
#-----| no-match -> in ... then ...
1053-
#-----| match -> exit case_match_various (normal)
1052+
#-----| -> foo
10541053

10551054
# 74| foo
1056-
#-----| -> ^...
1055+
#-----| no-match -> in ... then ...
1056+
#-----| match -> exit case_match_various (normal)
10571057

10581058
# 75| in ... then ...
10591059
#-----| -> "string"
@@ -1154,15 +1154,15 @@ case.rb:
11541154
#-----| -> 5
11551155

11561156
# 83| 5
1157-
#-----| no-match -> foo
1157+
#-----| no-match -> ^...
11581158
#-----| match -> exit case_match_various (normal)
11591159

11601160
# 83| ^...
1161-
#-----| no-match -> "string"
1162-
#-----| match -> exit case_match_various (normal)
1161+
#-----| -> foo
11631162

11641163
# 83| foo
1165-
#-----| -> ^...
1164+
#-----| no-match -> "string"
1165+
#-----| match -> exit case_match_various (normal)
11661166

11671167
# 83| "string"
11681168
#-----| no-match -> in ... then ...

0 commit comments

Comments
 (0)