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

Test against Rails 8 #2142

Open
3 tasks
KaanOzkan opened this issue Jan 7, 2025 · 4 comments
Open
3 tasks

Test against Rails 8 #2142

KaanOzkan opened this issue Jan 7, 2025 · 4 comments
Assignees

Comments

@KaanOzkan
Copy link
Contributor

KaanOzkan commented Jan 7, 2025

Rails "current" CI tests against 7.1.5 because it's the version specified in the Gemfile.

We should bump this version and start requiring CI checks on Rails 8 as a result.

Also there's no more active support for Rails 7.0 and 7.1 so it might be time to remove 7.0 from the CI.

  • 7.2
  • 8.0 (current)
  • main
@iMacTia
Copy link

iMacTia commented Jan 14, 2025

Thank you for raising this @KaanOzkan!
I'd like to raise that we seem to miss Rails 7.2 in CI as well.
We just realised there's an issue with the signature auto-generated for ActiveSupport::Duration#to_f (see this line).
Tapioca generates the following:

# source://activesupport//lib/active_support/duration.rb#224
def to_f(&_arg0); end

But looking at the implementation, it doesn't seem like #to_f really takes a block as input.
I'm unsure where this is coming from, but it wasn't there in Rails 7.1.x

@KaanOzkan
Copy link
Contributor Author

@iMacTia Rails 7.2 changed how that delegation works. I think it's adding an & argument here. So tapioca looks correct to me. I assume Rails has a reason for generating with an explicit optional block argument but I don't have context.

@caius
Copy link

caius commented Jan 15, 2025

Looks like it's accidentally finding the delegation methods take a block argument, they cascade to either Integer or Float (the @value instance variable inside an ActiveSupport::Duration object), neither of which have a #to_f implementation that calls a passed block.

Ruby does allow you to pass blocks to any method, so I guess the type signature isn't wrong, but in this case passing blocks isn't expected, nor do any of the delegated methods invoke a passed block. The documentation for Integer#to_f, Float#to_f shows no blocks are expected to be passed too.

As someone who doesn't understand much of the internals of Tapioca, I can see why this would be generating the signature it is, but that is then at odds with the documentation for those APIs, because they don't take blocks but it's typed as taking a block.

We've worked around it with a shim in our app currently, but it sounds to me like Tapioca might want to special-case these Delegate.generate calls in Rails.

# sorbet/rbi/shims/active_support.rb
class ActiveSupport::Duration
  # …

  sig { params(_arg0: T.proc.void).returns(Float) }
  def to_f(&_arg0); end

  # …
end

@andyw8
Copy link
Contributor

andyw8 commented Jan 21, 2025

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

5 participants