Discussion:
[jruby-user] JRuby head: splat (i.e., **args) method params?
Josep Blanquer
2014-09-02 21:52:03 UTC
Permalink
Hello,

It seems that as of the latest head from today:
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]

The following 2.1 syntax is not implemented?

ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11

Where that line is:

def initialize(name, context,**opts)


am I missing something to make that happen in the current codebase? or is
this a well know feature that still has to be implemented?

If the latter is true: do you have any inkling as to when that could be
done?

Thank you!

Josep M.
Thomas E Enebo
2014-09-02 22:50:11 UTC
Permalink
Can you give a more complete example. This works for me:

class Foo
def initialize(name, context,**opts)
p opts
end
end

Foo.new(1, 2, a: 1)

./bin/jruby -v snippets/kw15.rb
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.60-b09 on 1.7.0_60-b19 [darwin-x86_64]
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:92
warning: Ambiguous first argument; make sure.
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:96
warning: shadowing outer local variable - dir
{:a=>1}
Post by Josep Blanquer
Hello,
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]
The following 2.1 syntax is not implemented?
ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11
def initialize(name, context,**opts)
am I missing something to make that happen in the current codebase? or is
this a well know feature that still has to be implemented?
If the latter is true: do you have any inkling as to when that could be
done?
Thank you!
Josep M.
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com
Josep Blanquer
2014-09-03 04:45:39 UTC
Permalink
Aha! intersting...yes I can...so it seems a consequence of the "super"
method.
Here you have a repro:

------------------------------------------------------------
class Foo
def initialize(name, context,**opts)
p opts
end
end

class Bar < Foo
def initialize(name, context, path: nil)
super
end
end

Bar.new(1, 2)
Bar.new(1,2, path: "there")
------------------------------------------------------------

bug:foo $ rvm 2.1
bug:foo $ ruby /tmp/x.rb
{:path=>nil}
{:path=>"there"}
bug:foo $ rvm jruby-head
bug:foo $ ruby /tmp/x.rb
ArgumentError: wrong number of arguments (3 for 2)
initialize at /tmp/x.rb:9
initialize at /tmp/x.rb:9
(root) at /tmp/x.rb:13

while in MRI ruby both calls work (with and without the hash), in jruby
both fail with the arguments error.
So, something about the super call doesn't quite work as MRI does.

Cheers,

Josep M.
Post by Thomas E Enebo
class Foo
def initialize(name, context,**opts)
p opts
end
end
Foo.new(1, 2, a: 1)
./bin/jruby -v snippets/kw15.rb
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.60-b09 on 1.7.0_60-b19 [darwin-x86_64]
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:92
warning: Ambiguous first argument; make sure.
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:96
warning: shadowing outer local variable - dir
{:a=>1}
Post by Josep Blanquer
Hello,
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]
The following 2.1 syntax is not implemented?
ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11
def initialize(name, context,**opts)
am I missing something to make that happen in the current codebase? or is
this a well know feature that still has to be implemented?
If the latter is true: do you have any inkling as to when that could be
done?
Thank you!
Josep M.
--
blog: http://blog.enebo.com twitter: tom_enebo
Thomas E Enebo
2014-09-03 14:02:52 UTC
Permalink
Ah yeah. We are not delivering keyword arguments to zsuper. Thanks for
the simple reproduction. I made an issue for it:

https://github.com/jruby/jruby/issues/1943

-Tom
Post by Josep Blanquer
Aha! intersting...yes I can...so it seems a consequence of the "super"
method.
------------------------------------------------------------
class Foo
def initialize(name, context,**opts)
p opts
end
end
class Bar < Foo
def initialize(name, context, path: nil)
super
end
end
Bar.new(1, 2)
Bar.new(1,2, path: "there")
------------------------------------------------------------
bug:foo $ rvm 2.1
bug:foo $ ruby /tmp/x.rb
{:path=>nil}
{:path=>"there"}
bug:foo $ rvm jruby-head
bug:foo $ ruby /tmp/x.rb
ArgumentError: wrong number of arguments (3 for 2)
initialize at /tmp/x.rb:9
initialize at /tmp/x.rb:9
(root) at /tmp/x.rb:13
while in MRI ruby both calls work (with and without the hash), in jruby
both fail with the arguments error.
So, something about the super call doesn't quite work as MRI does.
Cheers,
Josep M.
Post by Thomas E Enebo
class Foo
def initialize(name, context,**opts)
p opts
end
end
Foo.new(1, 2, a: 1)
./bin/jruby -v snippets/kw15.rb
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.60-b09 on 1.7.0_60-b19 [darwin-x86_64]
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:92
warning: Ambiguous first argument; make sure.
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:96
warning: shadowing outer local variable - dir
{:a=>1}
Post by Josep Blanquer
Hello,
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]
The following 2.1 syntax is not implemented?
ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11
def initialize(name, context,**opts)
am I missing something to make that happen in the current codebase? or
is this a well know feature that still has to be implemented?
If the latter is true: do you have any inkling as to when that could be
done?
Thank you!
Josep M.
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com
Josep Blanquer
2014-09-03 15:23:43 UTC
Permalink
Thanks Thomas,

Do you have a ballpark sense as to how long something like this might take
to be solved? 1 week? 1 month? 6 months?

Josep M.
Post by Thomas E Enebo
Ah yeah. We are not delivering keyword arguments to zsuper. Thanks for
https://github.com/jruby/jruby/issues/1943
-Tom
Post by Josep Blanquer
Aha! intersting...yes I can...so it seems a consequence of the "super"
method.
------------------------------------------------------------
class Foo
def initialize(name, context,**opts)
p opts
end
end
class Bar < Foo
def initialize(name, context, path: nil)
super
end
end
Bar.new(1, 2)
Bar.new(1,2, path: "there")
------------------------------------------------------------
bug:foo $ rvm 2.1
bug:foo $ ruby /tmp/x.rb
{:path=>nil}
{:path=>"there"}
bug:foo $ rvm jruby-head
bug:foo $ ruby /tmp/x.rb
ArgumentError: wrong number of arguments (3 for 2)
initialize at /tmp/x.rb:9
initialize at /tmp/x.rb:9
(root) at /tmp/x.rb:13
while in MRI ruby both calls work (with and without the hash), in jruby
both fail with the arguments error.
So, something about the super call doesn't quite work as MRI does.
Cheers,
Josep M.
Post by Thomas E Enebo
class Foo
def initialize(name, context,**opts)
p opts
end
end
Foo.new(1, 2, a: 1)
./bin/jruby -v snippets/kw15.rb
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.60-b09 on 1.7.0_60-b19 [darwin-x86_64]
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:92
warning: Ambiguous first argument; make sure.
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:96
warning: shadowing outer local variable - dir
{:a=>1}
Post by Josep Blanquer
Hello,
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]
The following 2.1 syntax is not implemented?
ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11
def initialize(name, context,**opts)
am I missing something to make that happen in the current codebase? or
is this a well know feature that still has to be implemented?
If the latter is true: do you have any inkling as to when that could be
done?
Thank you!
Josep M.
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
Thomas E Enebo
2014-09-03 15:30:28 UTC
Permalink
1 week is most likely but this is easily worked around by just changing to
an explicit super (explicitly pass the args on) for the time being.

-Tom
Post by Josep Blanquer
Thanks Thomas,
Do you have a ballpark sense as to how long something like this might
take to be solved? 1 week? 1 month? 6 months?
Josep M.
Post by Thomas E Enebo
Ah yeah. We are not delivering keyword arguments to zsuper. Thanks for
https://github.com/jruby/jruby/issues/1943
-Tom
Post by Josep Blanquer
Aha! intersting...yes I can...so it seems a consequence of the "super"
method.
------------------------------------------------------------
class Foo
def initialize(name, context,**opts)
p opts
end
end
class Bar < Foo
def initialize(name, context, path: nil)
super
end
end
Bar.new(1, 2)
Bar.new(1,2, path: "there")
------------------------------------------------------------
bug:foo $ rvm 2.1
bug:foo $ ruby /tmp/x.rb
{:path=>nil}
{:path=>"there"}
bug:foo $ rvm jruby-head
bug:foo $ ruby /tmp/x.rb
ArgumentError: wrong number of arguments (3 for 2)
initialize at /tmp/x.rb:9
initialize at /tmp/x.rb:9
(root) at /tmp/x.rb:13
while in MRI ruby both calls work (with and without the hash), in jruby
both fail with the arguments error.
So, something about the super call doesn't quite work as MRI does.
Cheers,
Josep M.
Post by Thomas E Enebo
class Foo
def initialize(name, context,**opts)
p opts
end
end
Foo.new(1, 2, a: 1)
./bin/jruby -v snippets/kw15.rb
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java HotSpot(TM)
64-Bit Server VM 24.60-b09 on 1.7.0_60-b19 [darwin-x86_64]
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:92
warning: Ambiguous first argument; make sure.
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:96
warning: shadowing outer local variable - dir
{:a=>1}
Post by Josep Blanquer
Hello,
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java
HotSpot(TM) 64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]
The following 2.1 syntax is not implemented?
ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11
def initialize(name, context,**opts)
am I missing something to make that happen in the current codebase? or
is this a well know feature that still has to be implemented?
If the latter is true: do you have any inkling as to when that could
be done?
Thank you!
Josep M.
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
mail: ***@gmail.com
Josep Blanquer
2014-09-03 16:45:11 UTC
Permalink
Great, thanks for the prompt response Thomas.

So, we have just open sourced a lean API framework (
http://eng.rightscale.com/2014/08/22/unveiling_praxis.html) and it is very
much built using ruby 2.1 constructs, and I was trying to see if I could
run some simple apps using jruby-head. In that process I'm finding
incompatibilities (like the initial one about the super kwargs).

Patching that manually got me forward, but here's the next one I found (and
this time I've directly opened an issue):
https://github.com/jruby/jruby/issues/1944

in essence:
ruby-head :005 > Pathname.new("/tmp/foo").find
LocalJumpError: yield called out of block
from
/Users/blanquer/.rvm/rubies/jruby-head/lib/ruby/2.1/pathname.rb:1002:in
`find'
from /Users/blanquer/.rvm/rubies/jruby-head/lib/ruby/2.1/find.rb:47:in
`find'


Does that seem like a legitimate jruby bug?

Josep M.
Post by Thomas E Enebo
1 week is most likely but this is easily worked around by just changing to
an explicit super (explicitly pass the args on) for the time being.
-Tom
Post by Josep Blanquer
Thanks Thomas,
Do you have a ballpark sense as to how long something like this might
take to be solved? 1 week? 1 month? 6 months?
Josep M.
Post by Thomas E Enebo
Ah yeah. We are not delivering keyword arguments to zsuper. Thanks for
https://github.com/jruby/jruby/issues/1943
-Tom
Post by Josep Blanquer
Aha! intersting...yes I can...so it seems a consequence of the "super"
method.
------------------------------------------------------------
class Foo
def initialize(name, context,**opts)
p opts
end
end
class Bar < Foo
def initialize(name, context, path: nil)
super
end
end
Bar.new(1, 2)
Bar.new(1,2, path: "there")
------------------------------------------------------------
bug:foo $ rvm 2.1
bug:foo $ ruby /tmp/x.rb
{:path=>nil}
{:path=>"there"}
bug:foo $ rvm jruby-head
bug:foo $ ruby /tmp/x.rb
ArgumentError: wrong number of arguments (3 for 2)
initialize at /tmp/x.rb:9
initialize at /tmp/x.rb:9
(root) at /tmp/x.rb:13
while in MRI ruby both calls work (with and without the hash), in jruby
both fail with the arguments error.
So, something about the super call doesn't quite work as MRI does.
Cheers,
Josep M.
Post by Thomas E Enebo
class Foo
def initialize(name, context,**opts)
p opts
end
end
Foo.new(1, 2, a: 1)
./bin/jruby -v snippets/kw15.rb
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java
HotSpot(TM) 64-Bit Server VM 24.60-b09 on 1.7.0_60-b19 [darwin-x86_64]
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:92
warning: Ambiguous first argument; make sure.
/Users/enebo/work/jruby/lib/ruby/shared/rubygems/defaults/jruby.rb:96
warning: shadowing outer local variable - dir
{:a=>1}
On Tue, Sep 2, 2014 at 4:52 PM, Josep Blanquer <
Post by Josep Blanquer
Hello,
jruby 9000.dev-SNAPSHOT (2.1.2p142) 2014-09-02 8771d02 Java
HotSpot(TM) 64-Bit Server VM 24.0-b56 on 1.7.0_40-b43 [darwin-x86_64]
The following 2.1 syntax is not implemented?
ArgumentError: wrong number of arguments (3 for 2)
initialize at /...../file.rb:11
def initialize(name, context,**opts)
am I missing something to make that happen in the current codebase?
or is this a well know feature that still has to be implemented?
If the latter is true: do you have any inkling as to when that could
be done?
Thank you!
Josep M.
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
--
blog: http://blog.enebo.com twitter: tom_enebo
Loading...