Feature #7730

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

Added by Andrew Grimm about 1 year ago. Updated about 1 year ago.

[ruby-core:51580]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
Category:core
Target version:next minor

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.

0001-parse.y-warn-assigned-but-unused-in-toplevel.patch Magnifier (1.69 KB) Nobuyoshi Nakada, 01/23/2013 05:34 PM

Associated revisions

Revision 38982
Added by Nobuyoshi Nakada about 1 year ago

parse.y: warn assigned but unused in toplevel

  • parse.y (localpushgen): warn assigned but unused variables also in toplevel, except for -e option. [Feature #7730]

Revision 38998
Added by Nobuyoshi Nakada about 1 year ago

parse.y: no assigned but unused warnings in eval

  • parse.y (localpushgen): no assigned but unused variable warnings in eval as well as -e. [Feature #7730]

History

#1 Updated by Nobuyoshi Nakada about 1 year ago

Agree except for -e option.

#2 Updated by Koichi Sasada about 1 year ago

  • Category set to core
  • Assignee set to Nobuyoshi Nakada
  • Target version set to next minor

Nobu, do you need matz's approval?

#3 Updated by Nobuyoshi Nakada about 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r38982.
Andrew, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


parse.y: warn assigned but unused in toplevel

  • parse.y (localpushgen): warn assigned but unused variables also in toplevel, except for -e option. [Feature #7730]

Also available in: Atom PDF