Skip to content

jRuby 9050 and 9100 behave differently for case / when with Array from MRI #3897

@yoshidajun

Description

@yoshidajun

Environment:

jruby-9.0.5.0
jruby-9.1.0.0
ruby-2.2.4 ( MRI )

  • Mac OS X ( 10.11.4 El Capitan )
  • RVM 1.26.11
  • irb to run the code

Problem:

The following code returns different results between jRuby and MRI.

ALL = ['v0', 'v1']
vs = ['v0', 'v1']

case vs
when ALL then 1234
else
  raise 'Undefined'
end
  • MRI ( 2.2.4 ) returns 1234 ( good )
  • jRuby ( 9.0.5.0, 9.1.5.0 ) raises RuntimeError: 'Undefined' ( why? )

Stacktrace:

RuntimeError: Undefined
    from (irb):7:in `<eval>'
    from org/jruby/RubyKernel.java:983:in `eval'
    from org/jruby/RubyKernel.java:1290:in `loop'
    from org/jruby/RubyKernel.java:1103:in `catch'
    from org/jruby/RubyKernel.java:1103:in `catch'
    from /Users/yjun/.rvm/rubies/jruby-9.1.0.0/bin/irb:13:in `<top>'

Another code using if / else:

ALL = ['v0', 'v1']
vs = ['v0', 'v1']

if ALL === vs
  1234
else
  raise 'Undefined'
end

=> This code returns the same result ( 1234: good ).

I thought case a when b then c else d end is equivalent to if b === a then c else d end.
But it doesn't look like so.

Is this a known issue?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions