8000 Implement `Array#dig` and `Hash#dig` intrinsic by jez · Pull Request #6491 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Implement Array#dig and Hash#dig intrinsic #6491

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 8 commits into from
Oct 20, 2022
Merged

Implement Array#dig and Hash#dig intrinsic #6491

merged 8 commits into from
Oct 20, 2022

Conversation

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

Motivation

#6468

Test plan

See included automated tests.

@jez jez requested a review from a team as a code owner October 19, 2022 21:17
@jez jez requested review from froydnj and removed request for a team October 19, 2022 21:17
@jez
Copy link
Collaborator Author
jez commented Oct 19, 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_Me1jkvpSlKWnlg
https://go/builds/bui_Me1jytBNQW7Nr3

@jez
Copy link
Collaborator Author
jez commented Oct 19, 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_Me2VK5QEWfwzBc
https://go/builds/bui_Me2VG0DukBa9A3

args.locs.file, // file
args.locs.call.copyWithZeroLength(), // call
args.locs.args[0].copyWithZeroLength(), // receiver
args.locs.args[0].copyWithZeroLength(), // fun
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this just args.locs.fun? I don't know if it makes a difference whether you copyWithZeroLength(), but I think it would make things slightly more consistent to use args.locs.fun here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't think so?

opts.dig("first", "second")
     ^^^ fun
         ^^^^^^^ args[0]

Having it be zero length makes it basically ignore it for most things, and use the callLoc instead, except that it's very hard to get a case where it would need to use these errors, because we know that the Array#at / Hash#[] methods always exist, so we're unlikely to need the fun locs. The most important location in practice is the basecaseArgLocs in case you try to pass 0 to a T::Hash[String, ...] or something.

args.locs.file, // file
args.locs.args[1], // call
args.locs.receiver, // receiver
args.locs.args[1].copyWithZeroLength(), // fun
Copy link
Contributor

Choose a reason for hiding this comment

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

Also args.locs.funLoc. I guess we can use it as-is here, because the loc ought to be for dig, and that's what we're re-dispatching to?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Again, I think this is not funLoc, due to above.

Comment on lines +43 to +45
# Shapes are bad--ideally lot of these would be errors
sig {params(opts: AShapeType).void}
def example4(opts)
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO in the corresponding exp file says we should have some tuple tests too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

example7

jez and others added 3 commits October 20, 2022 11:28
Co-authored-by: Nathan Froyd <froydnj@gmail.com>
@jez jez requested a review from froydnj October 20, 2022 18:40
jez and others added 2 commits October 20, 2022 13:00
Co-authored-by: Nathan Froyd <froydnj@gmail.com>
@jez jez enabled auto-merge (squash) October 20, 2022 21:08
@jez jez merged commit 4717a64 into master Oct 20, 2022
@jez jez deleted the jez-dig branch October 20, 2022 21:26
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.

2 participants
0