Bug #2468 [ruby-core:27116]

Array expansion inside case/when gives unexpected results

Added by Romulo Ceccon 100 days ago. Updated 23 days ago.

Status :Closed Start :12/10/2009
Priority :Normal Due date :
Assigned to :- % Done :

100%

Category :core
Target version :Ruby 1.8.8
ruby -v :

ruby 1.8.8dev (2009-12-07 revision 26034) [i386-mswin32_90]


Description

Given the following script:

  arr = [1, 2, 3]

  case 2
  when 1, 2, 3
    puts "2 is in range #{arr.inspect}"
  else
    puts "2 is out of range #{arr.inspect}"
  end

  case 2
  when *arr # this is the only thing different from the previous statement
    puts "2 is in range #{arr.inspect}"
  else
    puts "2 is out of range #{arr.inspect}"
  end


Ruby 1.8.8dev gives me the following output:

  $ ruby -v
  ruby 1.8.8dev (2009-12-07 revision 26034) [i386-mswin32_90]

  $ ruby casebug.rb
  2 is in range [1, 2, 3]
  2 is out of range [1, 2, 3]


I'd expect the same results other versions give:

  $ ruby -v
  ruby 1.8.7 (2008-08-11 patchlevel 72) [i386-mswin32_90]

  $ ruby casebug.rb
  2 is in range [1, 2, 3]
  2 is in range [1, 2, 3]

  $ ruby -v
  ruby 1.9.1p129 (2009-05-12 revision 23412) [i386-mswin32]

  $ ruby casebug.rb
  2 is in range [1, 2, 3]
  2 is in range [1, 2, 3]

Related issues

related to Bug #2226 case 文の式が省略され when 節に配列展開があるときの挙動 Assigned
related to Bug #2555 "case n when *VALID" Broken in Ruby 1.8.8; affects Ruby on Rails Closed 01/05/2010
duplicates Bug #2551 case/when matches literal *[1,2,3] but not variable *ary Closed 01/03/2010

Associated revisions

Revision 26589
Added by knu 42 days ago

  • test/ruby/test_array.rb (TestArray#test_splat): Add test cases where splat fails in when clause. ref [Bug #2468]

History

02/06/2010 02:17 AM - Akinori MUSHA

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
This issue was solved with changeset r26589.
Romulo, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

02/08/2010 02:58 AM - Marc-Andre Lafortune

  • Status changed from Closed to Open

02/24/2010 01:26 PM - Yui NARUSE

  • Status changed from Open to Closed
> I wish "ref [Bug #...]" would have been parsed just like "cf: [Bug #...]".
#... may change when the ticket moves from bug to backport or something.
So writing ref #... is correct.

Also available in: Atom PDF