Skip to content

Commit b9258e7

Browse files
committed
Ruby: non-local variables in variable reference pattern
1 parent 966b8be commit b9258e7

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

ruby/ql/lib/codeql/ruby/ast/Pattern.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ class VariableReferencePattern extends CasePattern, TVariableReferencePattern {
418418
VariableReferencePattern() { this = TVariableReferencePattern(g) }
419419

420420
/** Gets the variable access corresponding to this variable reference pattern. */
421-
LocalVariableReadAccess getVariableAccess() { toGenerated(result) = g.getName() }
421+
VariableReadAccess getVariableAccess() { toGenerated(result) = g.getName() }
422422

423423
final override string getAPrimaryQlClass() { result = "VariableReferencePattern" }
424424

ruby/ql/test/library-tests/ast/Ast.expected

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,21 @@ control/cases.rb:
11151115
# 144| getClass: [ConstantReadAccess] Bar
11161116
# 144| getKey: [SymbolLiteral] :a
11171117
# 144| getValue: [IntegerLiteral] 1
1118+
# 147| getStmt: [CaseExpr] case ...
1119+
# 147| getValue: [MethodCall] call to expr
1120+
# 147| getReceiver: [Self, SelfVariableAccess] self
1121+
# 148| getBranch: [InClause] in ... then ...
1122+
# 148| getPattern: [VariableReferencePattern] ^...
1123+
# 148| getVariableAccess: [LocalVariableAccess] foo
1124+
# 149| getBranch: [InClause] in ... then ...
1125+
# 149| getPattern: [VariableReferencePattern] ^...
1126+
# 149| getVariableAccess: [GlobalVariableAccess] $foo
1127+
# 150| getBranch: [InClause] in ... then ...
1128+
# 150| getPattern: [VariableReferencePattern] ^...
1129+
# 150| getVariableAccess: [InstanceVariableAccess] @foo
1130+
# 151| getBranch: [InClause] in ... then ...
1131+
# 151| getPattern: [VariableReferencePattern] ^...
1132+
# 151| getVariableAccess: [ClassVariableAccess] @@foo
11181133
modules/classes.rb:
11191134
# 2| [Toplevel] classes.rb
11201135
# 3| getStmt: [ClassDeclaration] Foo

ruby/ql/test/library-tests/ast/ValueText.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@
236236
| control/cases.rb:142:11:142:11 | :y | :y |
237237
| control/cases.rb:144:11:144:11 | :a | :a |
238238
| control/cases.rb:144:14:144:14 | 1 | 1 |
239+
| control/cases.rb:148:7:148:9 | foo | 42 |
239240
| control/conditionals.rb:2:5:2:5 | 0 | 0 |
240241
| control/conditionals.rb:3:5:3:5 | 0 | 0 |
241242
| control/conditionals.rb:4:5:4:5 | 0 | 0 |

ruby/ql/test/library-tests/ast/control/CaseExpr.expected

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ caseValues
88
| cases.rb:116:1:124:3 | case ... | cases.rb:116:6:116:9 | call to expr |
99
| cases.rb:128:1:133:3 | case ... | cases.rb:128:6:128:9 | call to expr |
1010
| cases.rb:137:1:145:3 | case ... | cases.rb:137:6:137:9 | call to expr |
11+
| cases.rb:147:1:152:3 | case ... | cases.rb:147:6:147:9 | call to expr |
1112
caseNoValues
1213
| cases.rb:18:1:22:3 | case ... |
1314
caseElseBranches
@@ -22,6 +23,7 @@ caseNoElseBranches
2223
| cases.rb:116:1:124:3 | case ... |
2324
| cases.rb:128:1:133:3 | case ... |
2425
| cases.rb:137:1:145:3 | case ... |
26+
| cases.rb:147:1:152:3 | case ... |
2527
caseWhenBranches
2628
| cases.rb:8:1:15:3 | case ... | cases.rb:9:1:10:7 | when ... | 0 | cases.rb:9:6:9:6 | b | cases.rb:9:7:10:7 | then ... |
2729
| cases.rb:8:1:15:3 | case ... | cases.rb:11:1:12:7 | when ... | 0 | cases.rb:11:6:11:6 | c | cases.rb:11:10:12:7 | then ... |
@@ -121,3 +123,7 @@ caseAllBranches
121123
| cases.rb:137:1:145:3 | case ... | 4 | cases.rb:142:3:142:14 | in ... then ... |
122124
| cases.rb:137:1:145:3 | case ... | 5 | cases.rb:143:3:143:15 | in ... then ... |
123125
| cases.rb:137:1:145:3 | case ... | 6 | cases.rb:144:3:144:23 | in ... then ... |
126+
| cases.rb:147:1:152:3 | case ... | 0 | cases.rb:148:3:148:10 | in ... then ... |
127+
| cases.rb:147:1:152:3 | case ... | 1 | cases.rb:149:3:149:11 | in ... then ... |
128+
| cases.rb:147:1:152:3 | case ... | 2 | cases.rb:150:3:150:11 | in ... then ... |
129+
| cases.rb:147:1:152:3 | case ... | 3 | cases.rb:151:3:151:12 | in ... then ... |

ruby/ql/test/library-tests/ast/control/ControlExpr.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
| cases.rb:116:1:124:3 | case ... | CaseExpr |
99
| cases.rb:128:1:133:3 | case ... | CaseExpr |
1010
| cases.rb:137:1:145:3 | case ... | CaseExpr |
11+
| cases.rb:147:1:152:3 | case ... | CaseExpr |
1112
| conditionals.rb:10:1:12:3 | if ... | IfExpr |
1213
| conditionals.rb:15:1:19:3 | if ... | IfExpr |
1314
| conditionals.rb:22:1:30:3 | if ... | IfExpr |

ruby/ql/test/library-tests/ast/control/cases.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,9 @@
144144
in Bar( a: 1, **nil);
145145
end
146146

147+
case expr
148+
in ^foo;
149+
in ^$foo;
150+
in ^@foo;
151+
in ^@@foo;
152+
end

0 commit comments

Comments
 (0)