Local variable 'foo' may be uninitialized
Answered
I'm a java guy but sometimes it happens I have to look at some very old and very legacy ruby code. Every file I open ends peppered with warnings, the most annoying of which is "Local variable 'foo' may be unitialized". For example
def do_something(a, b, c)
some_sql = '...'
some_more_sql = '...'
open_connection do |db|
res = db.execute(some_sql, a, b, c)
if res.rows != 1
res = db.execute(some_more_sql, a, b, c)
if res.rows != 1
db.execute(some_sql, a, b, c)
end
end
end
end
RubyMine will highlight almost everything inside the inner block as possibly unitialized. What'up with that?
Please sign in to leave a comment.
Hello,
could you please specify your RubyMine version (I didn't manage to reproduce it in 2020.2.3 Preview)
I'm on 2020.2.2. It may have something to do with my settings, if I rename all the local variables with a leading underscore the warnings disappear.
So do you manage to reproduce the issue in a new project with the code sample you've provided?
I managed to reproduce the problem in a new project with a single file containing the above code. The issue is my setup: the original project is configured to use rbenv/ruby 1.8.7 ( don't ask ;-) ). Anything newer than tat has no problem.
Since Ruby 1.8.7 has reached its EOL we support it as it is with fixes related to some urgent security issues if there're any. It's also possible to disable that inspection in case you don't want to see it.