Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mruby-proc-ext: #parameters mistakes keyword "splat" for a block parameter #5066

Closed
ntl opened this issue Aug 14, 2020 · 2 comments
Closed

Comments

@ntl
Copy link
Contributor

ntl commented Aug 14, 2020

Hello, thanks so much for MRuby!

I'm currently investigating some behavior in Proc#parameters (from mrbgems/mruby-proc-ext), and believe I may have spotted a bug (or else I am unaware of the expected behavior). Here is a file that reproduces my issue (I put it in a test project under e.g. mrblib/bug_example.rb):

class BugExample
  def all_method(reqp, optp=nil, *restp, keyreqp:, keyp: nil, **keyrestp, &blockp)
    Invocation::Binding.get
  end
end

example = BugExample.new

puts example.method(:all_method).parameters.inspect

When I run the above code, with mruby-proc-ext (and mruby-io, for #puts), I see the following output:

[[:req, :reqp], [:opt, :optp], [:rest, :restp], [:block, :keyrestp]]

This indicates that the **keyrestp parameter has been interpreted as a block parameter. I'm not sure how keyword arguments are handled internally by MRuby, but I believe the expected output is this:

[[:req, :reqp], [:opt, :optp], [:rest, :restp], [:keyreq, :keyreqp], [:key, :keyp], [:keyrest, :keyrestp], [:block, :blockp]]

I'm not sure how mruby-proc-ext is supposed to work with keyword arguments. I have discovered that the keyword arguments appear to be placed in the stack after the block argument (and mrb->c->ci->argc does not indicate their presence; only ci_nregs in src/vm.c, line 405).

I am very new to MRuby, though, so I realize I may be in error here.

@ntl ntl changed the title mruby-proc-ext: #parameters mistakes keyword "splat" and block parameters mruby-proc-ext: #parameters mistakes keyword "splat" for a block parameter Aug 14, 2020
matz added a commit that referenced this issue Aug 17, 2020
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
@matz
Copy link
Member

matz commented Aug 17, 2020

It's fixed in the mruby3 branch.
Note that mruby's Proc#parameters does not distinguish required keyword arguments and optional keyword arguments.
It's a TODO.

@matz matz closed this as completed Aug 17, 2020
@ntl
Copy link
Contributor Author

ntl commented Aug 17, 2020

Thanks so much!

matz added a commit that referenced this issue Aug 31, 2020
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
matz added a commit that referenced this issue Sep 17, 2020
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
matz added a commit that referenced this issue Sep 18, 2020
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
matz added a commit that referenced this issue Sep 29, 2020
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
matz added a commit that referenced this issue Oct 14, 2020
TODO: Unlike CRuby, mruby's `Proc#parameters` does not distinguish
required keyword arguments and optional keyword arguments currently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants