JRuby

[1.9] Wrong block args handing

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: JRuby 1.4, JRuby 1.6.3
  • Fix Version/s: None
  • Component/s: Ruby 1.9.2
  • Labels:
    None
  • Number of attachments :
    0

Description

Consider the following:

ruby -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"

MRI produces:

[2, 1]
[3, 2]
3

JRuby produces totally wrong results:

jruby --1.9 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
2
3
1

The result of max is 1, which is totally wrong, and the block parameters are wrong.

Activity

Hide
Vladimir Sizikov added a comment -

Actually, MRI 1.9.2 behavior has just been changed too to something else:

See http://redmine.ruby-lang.org/issues/show/2184

ruby  -e 'order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)'
-e:1:in `each': wrong number of arguments (2 for 1) (ArgumentError)
        from -e:1:in `max'

Show
Vladimir Sizikov added a comment - Actually, MRI 1.9.2 behavior has just been changed too to something else: See http://redmine.ruby-lang.org/issues/show/2184
ruby  -e 'order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)'
-e:1:in `each': wrong number of arguments (2 for 1) (ArgumentError)
        from -e:1:in `max'

Hide
Charles Oliver Nutter added a comment -

Hmm....so 1.9 has started to strict up the argument processing. I suppose this should be questioned as to whether it's an intentional or accidental change. I know for a fact there's code out there that depends on getting an array tuple for hash#each elements...

Show
Charles Oliver Nutter added a comment - Hmm....so 1.9 has started to strict up the argument processing. I suppose this should be questioned as to whether it's an intentional or accidental change. I know for a fact there's code out there that depends on getting an array tuple for hash#each elements...
Hide
Charles Oliver Nutter added a comment -

Confirmed still broken in 1.6.3.

Show
Charles Oliver Nutter added a comment - Confirmed still broken in 1.6.3.
Hide
Charles Oliver Nutter added a comment -

Here's updated output. We still don't match 1.9.2/1.9.3's error, but since they error it's unlikely this code could be considered valid in the wild. Bug is still valid; we need to error the same.

system ~/projects/jruby $ ruby1.9.2 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
-e:1:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError)
	from -e:1:in `each'
	from -e:1:in `max'
	from -e:1:in `<main>'

system ~/projects/jruby $ rvm 1.9.3 do ruby -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
-e:1:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError)
	from -e:1:in `each'
	from -e:1:in `max'
	from -e:1:in `<main>'

system ~/projects/jruby $ jruby -v --1.9 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
jruby 1.6.6.dev (ruby-1.9.2-p312) (2012-01-17 1b8ce57) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
2
3
1

system ~/projects/jruby $ ../jruby2/bin/jruby -v --1.9 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
jruby 1.6.6.dev (ruby-1.9.2-p312) (2012-01-17 1b8ce57) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
2
3
1
Show
Charles Oliver Nutter added a comment - Here's updated output. We still don't match 1.9.2/1.9.3's error, but since they error it's unlikely this code could be considered valid in the wild. Bug is still valid; we need to error the same.
system ~/projects/jruby $ ruby1.9.2 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
-e:1:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError)
	from -e:1:in `each'
	from -e:1:in `max'
	from -e:1:in `<main>'

system ~/projects/jruby $ rvm 1.9.3 do ruby -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
-e:1:in `block in <main>': wrong number of arguments (2 for 1) (ArgumentError)
	from -e:1:in `each'
	from -e:1:in `max'
	from -e:1:in `<main>'

system ~/projects/jruby $ jruby -v --1.9 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
jruby 1.6.6.dev (ruby-1.9.2-p312) (2012-01-17 1b8ce57) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
2
3
1

system ~/projects/jruby $ ../jruby2/bin/jruby -v --1.9 -e "order = lambda {|x| p x; x[0] <=> x[1]}; p [1,2,3].max(&order)"
jruby 1.6.6.dev (ruby-1.9.2-p312) (2012-01-17 1b8ce57) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_29) [darwin-x86_64-java]
2
3
1

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: