-
Notifications
You must be signed in to change notification settings - Fork 121
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
ActiveRecord relations' each
method block argument is T.untyped
#2034
Comments
Adding these lines to my # https://github.com/Shopify/tapioca/issues/2034
ActiveRecord::Delegation.undef_method(:each) |
each
method block argument is T.untyped
Hi Mark, I think this list of delegated methods in That module is included after I think the fix here might be as easy as adding the correct sig to class ActiveRecord::Relation
sig { returns(T::Boolean) }
def blank?; end
+ # adapted from https://github.com/sorbet/sorbet/blob/64b1468/rbi/core/enumerable.rbi#L19-L27
+ sig do
+ abstract
+ .params(blk: T.proc.params(arg0: Elem).returns(BasicObject))
+ .returns(T.untyped)
+ end
+ sig { returns(T.self_type) }
+ def each(&blk); end
end That would be a great first contribution. Would you like to give it a shot? |
Sure, I'll give it a shot this week. I've been slammed with deadlines so I can't guarantee it but it sounds simple enough and may make it easier for me to contribute other fixes later. My workaround ended up breaking the usage of the .each method with no arguments anyway, since there was no concrete implementation of .each in the RBI, and Sorbet's Enumerable each sig returns T.self_type if used with no block. |
I think the second overload above instead of |
Calling
#each
on aPrivateAssociationRelation
,PrivateCollectionProxy
, etc. will give an untyped block argument. However,#each_with_index
will give a typed argument. This is difficult to work around (adding a line of code with aT.cast
for each time#each
is used, is not a workaround at all).These are classes which are also valid
Enumerable
s, but theeach
method on these classes will use the untypedActiveRecord::Delegation
methods from therbi/gems
path, and not a path defined inrbi/dsl
, or even sorbet'sT::Enumerable
class. This causes the block argument to be untyped, which causes a lot of missed type checking!!The text was updated successfully, but these errors were encountered: