-
Notifications
You must be signed in to change notification settings - Fork 565
Add T.bind for changing bindings inside procs and lambdas #4170
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
Conversation
I think this PR is also providing a solution for #230? |
a49f22e
to
e342768
Compare
I prefer in this PR, but if you wanted to do it in a follow up PR I wouldn't block this PR on it. |
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.
This looks great, thanks for those changes!
Some small suggested changes, and then waiting to hear back w.r.t. whether you want to do docs in this PR or another. I can merge as is or wait for the docs, just let me know.
Cool! I'll add the documentation to this PR and address the remaining comments, so that we can ship it all in one go. |
Co-authored-by: Jake Zimmerman <zimmerman.jake@gmail.com>
11ddf47
to
fa47097
Compare
Alright, added website documentation. Let me know if the copy looks good! |
@vinistock Does this actually close #4095? That issue requests a static error when using This PR implements an alternative for people who think that they want the behavior they imagine would be possible with I don't think we should expand the scope of this PR, but I am going to mark this PR as not closing that issue. |
We have a policy of testing changes to Sorbet against Stripe's codebase before Stripe employees can see the build results here: → https://go/builds/bui_JOUwqSiKKgp6Fd |
Thanks! |
This PR introduces
T.bind
outside of the context of method signatures to allow users to bind procs and lambdas to different types. This is especially useful in the Rails world, where a lot of procs are executed withinstance_exec
.For example,
With the changes in this PR, users can indicate the correct binding inside each proc, guaranteeing that type checking is verifying against the right types. Below is an example usage and more examples can be found in the tests included.
Motivation
Sorbet currently does not allow indicating the context in which a captured block will run, which limits typing in common Rails use cases, such as the previously mentioned callbacks, but also active support concerns.
Test plan
The included tests display examples for concerns and callbacks.