Skip to content

Commit ae0c9b7

Browse files
authored
Merge pull request github#10843 from aibaars/fix-self
Ruby: fix self variables in blocks
2 parents 2c5129e + a8fdda6 commit ae0c9b7

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

ruby/ql/lib/codeql/ruby/ast/internal/Variable.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,9 @@ private class SelfVariableAccessReal extends SelfVariableAccessImpl, TSelfReal {
676676
private SelfVariable var;
677677

678678
SelfVariableAccessReal() {
679-
exists(Ruby::Self self | this = TSelfReal(self) and var = TSelfVariable(scopeOf(self)))
679+
exists(Ruby::Self self |
680+
this = TSelfReal(self) and var = TSelfVariable(scopeOf(self).getEnclosingSelfScope())
681+
)
680682
}
681683

682684
final override SelfVariable getVariableImpl() { result = var }

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3696,7 +3696,7 @@ cfg.rb:
36963696
#-----| -> exit filter_nil
36973697

36983698
# 207| filter_nil
3699-
#-----| -> exit cfg.rb (normal)
3699+
#-----| -> self
37003700

37013701
# 207| list
37023702
#-----| -> list
@@ -3733,6 +3733,35 @@ cfg.rb:
37333733
# 209| call to nil?
37343734
#-----| -> exit do ... end (normal)
37353735

3736+
# 213| call to do_something
3737+
#-----| -> exit cfg.rb (normal)
3738+
3739+
# 213| self
3740+
#-----| -> do ... end
3741+
3742+
# 213| do ... end
3743+
#-----| -> call to do_something
3744+
3745+
# 213| enter do ... end
3746+
#-----| -> self
3747+
3748+
# 213| exit do ... end
3749+
3750+
# 213| exit do ... end (normal)
3751+
#-----| -> exit do ... end
3752+
3753+
# 214| self
3754+
#-----| -> call to something
3755+
3756+
# 214| call to something
3757+
#-----| -> self
3758+
3759+
# 215| call to something_else
3760+
#-----| -> exit do ... end (normal)
3761+
3762+
# 215| self
3763+
#-----| -> call to something_else
3764+
37363765
desugar.rb:
37373766
# 1| enter m1
37383767
#-----| -> x

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ callsWithNoArguments
4444
| cfg.rb:205:1:205:3 | call to foo |
4545
| cfg.rb:208:3:210:5 | call to reject |
4646
| cfg.rb:209:5:209:13 | call to nil? |
47+
| cfg.rb:213:1:216:3 | call to do_something |
48+
| cfg.rb:214:3:214:16 | call to something |
49+
| cfg.rb:215:3:215:16 | call to something_else |
4750
| desugar.rb:6:3:6:7 | call to foo |
4851
| desugar.rb:10:3:10:7 | call to foo |
4952
| desugar.rb:14:3:14:7 | call to foo |

ruby/ql/test/library-tests/controlflow/graph/cfg.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ def filter_nil list
210210
end
211211
end
212212

213+
do_something do
214+
self.something
215+
something_else
216+
end
217+
213218
__END__
214219

215220
Some ignored nonsense

0 commit comments

Comments
 (0)