Project

General

Profile

Feature #7730

Top level variables aren't checked for assigned but unused behavior

Added by agrimm (Andrew Grimm) over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Normal
Target version:
[ruby-core:51580]

Description

In the following code, variable a in the method gets a warning, but variable b in top level code doesn't get any warning

def warning_method
  a = 2
end

b = 2
warning_method

$ ruby -w no_toplevel_warnings.rb 
no_toplevel_warnings.rb:2: warning: assigned but unused variable - a

It is possible to detect that b is unused if the script is required from another script.

I'd like Ruby to be able to detect that b is an assigned but unused variable.


Files

Also available in: Atom PDF