Project

General

Profile

Bug #1626

Set Raises NoMethodError for Non-Enumerable Arguments

Added by runpaint (Run Paint Run Run) over 11 years ago. Updated over 9 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 1.9.2dev (2009-06-13 trunk 23682) [i686-linux]
Backport:
[ruby-core:23844]

Description

=begin
Attempting to construct a Set on 1.9 with a non-Enumerable argument causes a NoMethodError to be raised, which is unintuitive.

 $ ruby -rset -ve 'Set.new 3'
 ruby 1.9.2dev (2009-06-13 trunk 23682) [i686-linux]
 /usr/local/lib/ruby/1.9.1/set.rb:282:in `merge': undefined method `each' for 3:Fixnum (NoMethodError)
from /usr/local/lib/ruby/1.9.1/set.rb:75:in `initialize'
from -e:1:in `new'
from -e:1:in `<main>'

1.8 raises an ArgumentError for this scenario, which is far more sensible.

 $ ruby1.8 -rset -ve 'Set.new 3'
 ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]
 /usr/lib/ruby/1.8/set.rb:262:in `merge': value must be enumerable (ArgumentError)
from /usr/lib/ruby/1.8/set.rb:75:in `initialize'
from -e:1:in `new'
from -e:1

=end

#1

Updated by yugui (Yuki Sonoda) over 11 years ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)
  • Target version set to 1.9.2

=begin

=end

#2

Updated by marcandre (Marc-Andre Lafortune) almost 11 years ago

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

=begin
This issue was solved with changeset r26120.
Run Paint, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

#3

Updated by marcandre (Marc-Andre Lafortune) almost 11 years ago

=begin
These checks were removed 4 years ago in r8676 (git:639bd5e78) without no comment in the logs. Tests were changed in r8719 (git:3285c92). I added back the checks that were needed (plus one for the creator called with a block for both 1.8 & 1.9).

lib/set now passes rubyspec on trunk.

=end

Also available in: Atom PDF