Project

General

Profile

Actions

Bug #9623

closed

warning: "named capture conflicts a local variable" does not allow loops with named captures

Added by drbrain (Eric Hodel) about 10 years ago. Updated over 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
Backport:
[ruby-core:61423]

Description

Given the following example:

args = []

remaining = 'a,b,c'

begin
  /(?<token>[^,]*),?(?<remaining>.*)/ =~ remaining

  args << token
end until remaining.empty?

p args

Gives a warning with -w: test.rb:6: warning: named capture conflicts a local variable - remaining

I'm unsure if the warning is useful here. Reassigning in the loop through the named captures seems clearer than using the regexp globals.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #12359: Named captures "conflict" warning is unnecessary and limits uses of named capturesClosedActions
Actions #1

Updated by Eregon (Benoit Daloze) almost 8 years ago

  • Related to Bug #12359: Named captures "conflict" warning is unnecessary and limits uses of named captures added

Updated by jeremyevans0 (Jeremy Evans) over 4 years ago

  • Status changed from Open to Closed
  • Backport deleted (1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN)
Actions

Also available in: Atom PDF

Like0
Like0Like0