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

Bug generating RBI for Rails 6.0.3, Ruby 2.7 #2994

Closed
hdoan741 opened this issue May 10, 2020 · 5 comments
Closed

Bug generating RBI for Rails 6.0.3, Ruby 2.7 #2994

hdoan741 opened this issue May 10, 2020 · 5 comments
Labels
bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team

Comments

@hdoan741
Copy link
Contributor

There are generation errors in Ruby 2.7. It seems to happen in the last few days. I found it out via. Sorbet-rails automated tests.

Sample errors: (notice the double ** and double &&)

sorbet/rbi/gems/activerecord.rbi:2489: unexpected token tAMPER https://srb.help/2001
    2489 |  def rotate(**, &&); end
                            ^
sorbet/rbi/gems/activerecord.rbi:2490: unexpected token tAMPER https://srb.help/2001
    2490 |  def sample(**, &&); end
@hdoan741 hdoan741 added bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team labels May 10, 2020
@jaredbeck
Copy link
Contributor

jaredbeck commented May 19, 2020

See also:

@connorshea
Copy link
Contributor

connorshea commented Jun 6, 2020

I did a bit of investigating and found that the behavior indeed differs between versions:

# 2.6:
irb(main):003:0> ActiveRecord::Delegation.instance_method(:rotate).parameters
=> [[:rest, :args], [:block, :block]]

# 2.7:
irb(main):008:0> ActiveRecord::Delegation.instance_method(:rotate).parameters
=> [[:rest, :*], [:block, :&]]

Seems to be caused by this line on Ruby 2.7: https://github.com/rails/rails/blob/1b3a0a0388cea93ba33e6a951a3ac0aa2e4a8ed7/activerecord/lib/active_record/relation/delegation.rb#L64

There's no special parameters return type for the delegation syntax, but there is an issue to create it: https://bugs.ruby-lang.org/issues/16456

We could explicitly add a check for [[:rest, :*] and [:block, :&]] and correct it to *args and &block for now, but it'd be a bit of a hack.

EDIT: Apparently the 'hack' is the expected solution 🤷‍♂️

@bmulholland
Copy link

I switched to Tapioca and, with these steps, am successfully using Sorbet with Ruby 2.7. This works because Tapioca generates RBI files with *args and &block instead of the new syntax.

@connorshea
Copy link
Contributor

I also chose to resolve this by switching to Tapioca.

@jez
Copy link
Collaborator

jez commented Jul 27, 2022

Going to close this in favor of Tapioca

https://sorbet.org/blog/2022/07/27/srb-tapioca

@jez jez closed this as not planned Won't fix, can't repro, duplicate, stale Jul 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed This issue has not yet been confirmed by the Sorbet team
Projects
None yet
Development

No branches or pull requests

6 participants