-
Notifications
You must be signed in to change notification settings - Fork 565
Add error for non-Proc
-typed block argument
#6486
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
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_MdfW1NQlJLbJsV |
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
72cf5c9
to
5cebbe3
Compare
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_MdgHIDMkIMepod |
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.
More errors is more better.
resolver/type_syntax/type_syntax.h
Outdated
core::Loc nameLoc; | ||
core::NameRef name; | ||
core::Loc typeLoc; | ||
core::TypePtr type; | ||
core::ClassOrModuleRef rebind; |
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.
I think this struct packs slightly better after this change if you move rebind
prior to type
.
e.setHeader("Block argument type must be either `{}` or a `{}` type (and possibly nilable)", | ||
"Proc", "T.proc"); | ||
e.addErrorNote( | ||
"Ruby allows classes to have custom `{}` methods to convert `{}`-passed arguments into\n" | ||
" `{}` objects, but even those methods must return `{}` objects.", | ||
"to_proc", "&blk", "Proc", "Proc"); |
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.
OOC, do we have tests for honoring this magic to_proc
behavior?
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.
sort of but they could be better. i added one.
resolver/resolver.cc
Outdated
" `{}` objects, but even those methods must return `{}` objects.", | ||
"to_proc", "&blk", "Proc", "Proc"); | ||
|
||
e.replaceWith("Convert block to `T.nilable(Proc)`", spec->typeLoc, "T.nilable(Proc)"); |
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.
e.replaceWith("Convert block to `T.nilable(Proc)`", spec->typeLoc, "T.nilable(Proc)"); | |
e.replaceWith("Change block type to `T.nilable(Proc)`", spec->typeLoc, "T.nilable(Proc)"); |
This doesn't actually work in the Ruby VM, and neither does it work in sorbet-runtime.
This approximates the behavior that used to happen when `BasicObject` used to be used as a `&blk` arg type.
8f134e7
to
f13ff3e
Compare
Motivation
Fixes #6483
The Ruby VM does not allow this.
Test plan
See included automated tests.