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

Do not emit unexpected keyword rest by rbs prototype rb #163

Merged
merged 1 commit into from
Jan 2, 2020

Conversation

pocke
Copy link
Member

@pocke pocke commented Jan 2, 2020

Problem

rbs prototype rb command generates kwrest argument unexpectedly if the method as keyword argument(s).

# a.rb
class C
  def foo(x:) end
end
$ exe/rbs prototype rb a.rb
# a.rb
class C
  def foo: (x: untyped x, **untyped) -> untyped
end

Cause

Because a kwrest node is not falsy if the method has keyword arguments.

pp RubyVM::AbstractSyntaxTree.parse <<~RUBY
  def with_keyword_arg(x:) end
  def without_keyowrd_arg(x) end
RUBY
(SCOPE@1:0-2:30
 tbl: []
 args: nil
 body:
   (BLOCK@1:0-2:30
      (DEFN@1:0-1:28
       mid: :with_keyword_arg
       body:
         (SCOPE@1:0-1:28
          tbl: [:x, nil]
          args:
            (ARGS@1:21-1:23
             pre_num: 0
             pre_init: nil
             opt: nil
             first_post: nil
             post_num: 0
             post_init: nil
             rest: nil
             kw:
               (KW_ARG@1:21-1:23
                  (LASGN@1:21-1:23 :x :NODE_SPECIAL_REQUIRED_KEYWORD) nil)
             kwrest: (DVAR@1:21-1:23 nil)
             block: nil)
          body: nil))
      (DEFN@2:0-2:30
       mid: :without_keyowrd_arg
       body:
         (SCOPE@2:0-2:30
          tbl: [:x]
          args:
            (ARGS@2:24-2:25
             pre_num: 1
             pre_init: nil
             opt: nil
             first_post: nil
             post_num: 0
             post_init: nil
             rest: nil
             kw: nil
             kwrest: nil
             block: nil)
          body: nil))))

This pull request will fix the problem.

@soutaro
Copy link
Member

soutaro commented Jan 2, 2020

Good catch!

@soutaro soutaro merged commit e69808d into ruby:master Jan 2, 2020
@pocke pocke deleted the kwrest-rb-prototype branch January 2, 2020 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants