Project

General

Profile

Actions

Bug #2551

closed

case/when matches literal *[1,2,3] but not variable *ary

Added by bitsweat (Jeremy Daer) almost 15 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.8.8dev (2010-01-01 revision 26212) [i386-darwin10.2.0]
[ruby-core:27378]

Description

=begin
Matching a splat works with a literal but not a variable:

$ irb188

case 42; when *[41..43]; true end
=> true
a = [41..43]
=> [41..43]
case 42; when *a; true end
=> nil

Behaves correctly on 1.9.2dev and 1.8.7:

$ irb192

RUBY_DESCRIPTION
=> "ruby 1.9.2dev (2010-01-03 trunk 26233) [x86_64-darwin10.2.0]"
case 42; when *[41..43]; true end
=> true
a = [41..43]
=> [41..43]
case 42; when *a; true end
=> true

This breaks a lot of code, such as the Builder library which escapes all values as '***' on 1.8.8dev.

A test case:

diff --git a/test/ruby/test_case.rb b/test/ruby/test_case.rb
index af925d1..f996ed6 100644
--- a/test/ruby/test_case.rb
+++ b/test/ruby/test_case.rb
@@ -52,5 +52,13 @@ class TestCase < Test::Unit::TestCase
else
assert(false)
end
+

  • range = [41..43]
  • case 42
  • when *range
  •  assert(true)
    
  • else
  •  assert(false)
    
  • end
    end
    end
    =end

Related issues 2 (0 open2 closed)

Is duplicate of Ruby 1.8 - Bug #2468: Array expansion inside case/when gives unexpected resultsClosed12/10/2009Actions
Has duplicate Ruby 1.8 - Bug #2555: "case n when *VALID" Broken in Ruby 1.8.8; affects Ruby on RailsClosed01/05/2010Actions
Actions #1

Updated by bitsweat (Jeremy Daer) almost 15 years ago

=begin
Duplicates #2468.
=end

Actions #2

Updated by bitsweat (Jeremy Daer) almost 15 years ago

=begin
This is a show-stopper bug that affects a lot of my code. If it's not going to be fixed, perhaps the 19migration/looser_args merge should be reverted.
=end

Actions #3

Updated by knu (Akinori MUSHA) almost 15 years ago

  • Status changed from Open to Closed

=begin
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.

=end

Actions #4

Updated by bitsweat (Jeremy Daer) almost 15 years ago

=begin
r26589 adds a failing test case but no fix. Please reopen.
=end

Actions #5

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

  • Status changed from Closed to Open

=begin

=end

Actions #6

Updated by naruse (Yui NARUSE) almost 15 years ago

  • Status changed from Open to Closed

=begin

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.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0