Ruby: fix self variables in blocks

This commit is contained in:
Arthur Baars 2022-10-14 16:02:39 +02:00
Родитель 9abd599024
Коммит a8fdda65fb
4 изменённых файлов: 41 добавлений и 2 удалений

Просмотреть файл

@ -676,7 +676,9 @@ private class SelfVariableAccessReal extends SelfVariableAccessImpl, TSelfReal {
private SelfVariable var;
SelfVariableAccessReal() {
exists(Ruby::Self self | this = TSelfReal(self) and var = TSelfVariable(scopeOf(self)))
exists(Ruby::Self self |
this = TSelfReal(self) and var = TSelfVariable(scopeOf(self).getEnclosingSelfScope())
)
}
final override SelfVariable getVariableImpl() { result = var }

Просмотреть файл

@ -3696,7 +3696,7 @@ cfg.rb:
#-----| -> exit filter_nil
# 207| filter_nil
#-----| -> exit cfg.rb (normal)
#-----| -> self
# 207| list
#-----| -> list
@ -3733,6 +3733,35 @@ cfg.rb:
# 209| call to nil?
#-----| -> exit do ... end (normal)
# 213| call to do_something
#-----| -> exit cfg.rb (normal)
# 213| self
#-----| -> do ... end
# 213| do ... end
#-----| -> call to do_something
# 213| enter do ... end
#-----| -> self
# 213| exit do ... end
# 213| exit do ... end (normal)
#-----| -> exit do ... end
# 214| self
#-----| -> call to something
# 214| call to something
#-----| -> self
# 215| call to something_else
#-----| -> exit do ... end (normal)
# 215| self
#-----| -> call to something_else
desugar.rb:
# 1| enter m1
#-----| -> x

Просмотреть файл

@ -44,6 +44,9 @@ callsWithNoArguments
| cfg.rb:205:1:205:3 | call to foo |
| cfg.rb:208:3:210:5 | call to reject |
| cfg.rb:209:5:209:13 | call to nil? |
| cfg.rb:213:1:216:3 | call to do_something |
| cfg.rb:214:3:214:16 | call to something |
| cfg.rb:215:3:215:16 | call to something_else |
| desugar.rb:6:3:6:7 | call to foo |
| desugar.rb:10:3:10:7 | call to foo |
| desugar.rb:14:3:14:7 | call to foo |

Просмотреть файл

@ -210,6 +210,11 @@ def filter_nil list
end
end
do_something do
self.something
something_else
end
__END__
Some ignored nonsense