-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add support for #to_a
in ActiveRecord relations compiler
#1701
Add support for #to_a
in ActiveRecord relations compiler
#1701
Conversation
These relation classes already have
As for |
Here is a sorbet.run demo I created from the generated relation file to show that |
Oh, weird. The whole reason I opened this PR is because I got a |
It turns out This is because Rails explicitly aliases @paracycle How do you think this should be handled? Should the relations compiler use |
Ah ok, thanks for the explanation.
I find being explicit in RBI files to be better, so I tend to not use |
8467180
to
0964d42
Compare
#to_a
and #to_ary
methods to ActiveRecord relations compiler#to_a
inActiveRecord relations compiler
#to_a
inActiveRecord relations compiler#to_a
in ActiveRecord relations compiler
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks great. You'll need to run bin/docs
and commit the result, since you've made a docs change as well.
0964d42
to
27823c9
Compare
Motivation
This PR adds support for
#to_a
to the ActiveRecord relations compiler.Sorbet can usually infer that
#to_a
returns the same type as#to_ary
, but because Active Record explicitly aliases#to_ary
to#to_a
(here), Sorbet thinks#to_a
is a separate method with no signature and thus returnsT.untyped
.Cf. sorbet.run bug repro.
Implementation
Updated every place where a signature is defined for
#to_ary
to also define the same signature for#to_a
, with the exception of the signature that returnsNilClass
(cf. comment below).Tests
Updated the existing test for the compiler with the new signatures.