10000 Adding sig to freeze method by che-burashco · Pull Request #3152 · sorbet/sorbet · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Adding sig to freeze method #3152

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 1 commit into from
Jun 4, 2020
Merged

Conversation

che-burashco
Copy link
Contributor

Added the sig to the freeze method of the String

Motivation

When defining the constants in Ruby, it's quite common to define them as frozen literals so that they are immutable. As a result code like this MY_CONST = T.let('my_const'.freeze, String) is failing the type check

Test plan

Added a quick one line test for the method

@che-burashco che-burashco requested a review from a team as a code owner June 4, 2020 19:05
@che-burashco che-burashco requested review from elliottt and removed request for a team June 4, 2020 19:05
@che-burashco
Copy link
Contributor Author

On a tangential note, it would be interesting to add the notation that says that the intrinsic state of the object is changeable by the method annotated. This way it could potentially be possible to have return types that represent frozen classes where such method calls are forbidden.

Example
Right now Sorbet will allow the following code:

string = 'string'.frozen
string << 'additional'

Ruby will throw an error in the runtime though

@elliottt
Copy link
Collaborator
elliottt commented Jun 4, 2020

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 result here:

https://go/builds/bui_HPDjIVprlu1th5

Copy link
Collaborator
@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

Thanks!

@elliottt elliottt merged commit 34c2568 into sorbet:master Jun 4, 2020
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