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

Revert "Make ActiveRecord#find return value typed" #1101

Merged
merged 1 commit into from
Aug 8, 2022

Conversation

paracycle
Copy link
Member

@paracycle paracycle commented Aug 8, 2022

Reverts #1089

The PR was merged, but the implementation is flawed and will not work in real applications.

Union types as return values don't work the way folks imagine them to work:

user = User.find(1)

user.name # Method name does not exist on T::Array[User] component of T.any(T::Array[User], User)

sorbet.run link

@paracycle paracycle requested a review from a team as a code owner August 8, 2022 16:13
@vinistock
Copy link
Member

I know this is not the point of this PR, but I wanted to call attention to the fact that Sorbet has started accepting overloaded method signatures (example).

Could we (in a follow up PR) change this generator to add two signatures? One that accepts and returns an array and another one that accepts a string or integer and returns a single record?

@paracycle
Copy link
Member Author

I know this is not the point of this PR, but I wanted to call attention to the fact that Sorbet has started accepting overloaded method signatures (example).

Could we (in a follow up PR) change this generator to add two signatures? One that accepts and returns an array and another one that accepts a string or integer and returns a single record?

Sorbet has always accepted overloaded signatures in the payload since the beginning. But that is only guaranteed to work in # typed: __STDLIB_INTERNAL files which are supposed to be files in the payload.

I'd made a case for making that possible in all RBI files, which was met with a hesitantly warm reception, but there are edge cases to consider.

@paracycle paracycle merged commit 285b5e5 into main Aug 8, 2022
@paracycle paracycle deleted the revert-1089-typed-active-record-find branch August 8, 2022 17:01
@shopify-shipit shopify-shipit bot temporarily deployed to production August 31, 2022 14:40 Inactive
@andredriem
Copy link

I know this is not the point of this PR, but I wanted to call attention to the fact that Sorbet has started accepting overloaded method signatures (example).
Could we (in a follow up PR) change this generator to add two signatures? One that accepts and returns an array and another one that accepts a string or integer and returns a single record?

Sorbet has always accepted overloaded signatures in the payload since the beginning. But that is only guaranteed to work in # typed: __STDLIB_INTERNAL files which are supposed to be files in the payload.

I'd made a case for making that possible in all RBI files, which was met with a hesitantly warm reception, but there are edge cases to consider.

Those links are private now. Is there any news regarding the overloaded signatures?

@Morriar
Copy link
Collaborator

Morriar commented Oct 26, 2023

Is there any news regarding the overloaded signatures?

Overloads are now allowed in RBI files as an experimental feature: https://sorbet.org/docs/overloads.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants