Project

General

Profile

Bug #15188

Incorrect warning "assigned but unused variable" when using ripper with $VERBOSE = true

Added by cout (Paul Brannan) about 1 year ago. Updated 6 days ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
[ruby-core:89236]

Description

The following code:

require 'ripper'

class Parser < Ripper
  def warn(fmt, *args)
    puts "#{filename}:#{lineno} - #{fmt % args}"
  end
end

if __FILE__ == $0 then
  $VERBOSE = true

  s = 'foo = 42; p foo'
  parser = Parser.new(s)
  parser.parse
end

produces this warning:

(ripper):1 - assigned but unused variable - foo

but clearly foo is not unused.


Files

ripper-assign-unused-15188.patch (1004 Bytes) ripper-assign-unused-15188.patch jeremyevans0 (Jeremy Evans), 08/27/2019 07:00 PM

Associated revisions

Revision 447d5835
Added by jeremyevans (Jeremy Evans) 6 days ago

Silence incorrect assigned but unused variable warnings in ripper

To only emit the warnings in correct cases would require tracking
local variable usage in ripper, which ripper currently does not do.

Fixes [Bug #15188]

History

#1

Updated by nagachika (Tomoyuki Chikanaga) about 1 year ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

Ripper doesn't track usage of local variables as far as I can see. In parse.y, LVAR_USED is used to mark local variables as being used. In normal compilation mode, this is set by mark_lvar_used, called by value_expr_check, called by value_expr_gen (aliased to value_expr). In ripper mode, #define value_expr(node) ((void)(node)). It seems best to just not attempt to print unused variable warnings in ripper, which the attached patch does.

#3

Updated by jeremyevans (Jeremy Evans) 6 days ago

  • Status changed from Open to Closed

Applied in changeset git|447d583536274a2489efc8792653ad35d6f7128a.


Silence incorrect assigned but unused variable warnings in ripper

To only emit the warnings in correct cases would require tracking
local variable usage in ripper, which ripper currently does not do.

Fixes [Bug #15188]

Also available in: Atom PDF