8000 Add error for non-`Proc`-typed block argument by jez · Pull Request #6486 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 9 commits into from
Oct 20, 2022
Merged

Add error for non-Proc-typed block argument #6486

merged 9 commits into from
Oct 20, 2022

Conversation

jez
Copy link
Collaborator
@jez jez commented Oct 18, 2022

Motivation

Fixes #6483

The Ruby VM does not allow this.

Test plan

See included automated tests.

@jez jez requested a review from a team as a code owner October 18, 2022 22:20
@jez jez requested review from froydnj and removed request for a team October 18, 2022 22:20
@jez
Copy link
Collaborator Author
jez commented Oct 18, 2022

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_MdfW1NQlJLbJsV
https://go/builds/bui_MdfWyr8Bkurxqp

@jez jez changed the base branch from master to jez-crash-get-call-args October 18, 2022 23:07
@jez
Copy link
Collaborator Author
jez commented Oct 18, 2022

Current dependencies on/for this PR:

This comment was auto-generated by Graphite.

@jez
Copy link
Collaborator Author
jez commented Oct 18, 2022

We have a policy of testing changes to Sorbet against Stripe's codebase before
merging them. I've kicked off a test run for the current PR. When the build
finishes, I'll share with you whether or how it failed. Thanks!

Stripe employees can see the build results here:

https://go/builds/bui_MdgHIDMkIMepod
https://go/builds/bui_MdgIJZO7YDXSbO

Copy link
Contributor
@froydnj froydnj left a 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.

Comment on lines 13 to 17
core::Loc nameLoc;
core::NameRef name;
core::Loc typeLoc;
core::TypePtr type;
core::ClassOrModuleRef rebind;
Copy link
Contributor

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.

Comment on lines +3450 to +3455
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");
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

" `{}` 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)");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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)");

Base automatically changed from jez-crash-get-call-args to master October 20, 2022 18:55
jez added 7 commits October 20, 2022 11:56
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.
@jez jez force-pushed the jez-reject-non-proc branch from 8f134e7 to f13ff3e Compare October 20, 2022 19:02
@jez jez enabled auto-merge (squash) October 20, 2022 19:57
@jez jez merged commit efdc4fc into master Oct 20, 2022
@jez jez deleted the jez-reject-non-proc branch October 20, 2022 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sorbet should not allow non-Proc types for &blk arguments
2 participants
0