Do not pass T.untyped to ObjectSpace::WeakMap#1303
Merged
paracycle merged 5 commits intoShopify:mainfrom Dec 14, 2022
Merged
Conversation
In sorbet/sorbet#6610 type_member changed from `out` to `fixed: T.untyped`. From this point we should not pass explicit `T.untyped` as argument to generic type.
T.untyped to ObjectSpace::WeakMapT.untyped to ObjectSpace::WeakMap
Morriar
reviewed
Dec 12, 2022
3 tasks
Adds support for using `ObjectSpace::WeakMap` without a generic type argument. This change is guarded by a check for the availability of a specific Sorbet feature (`non_generic_weak_map`), which is required for this change to be applied. This update allows Tapioca to use the non-generic version of `WeakMap` when running on a version of Sorbet that supports it, while still providing support for earlier versions that require the generic type argument.
Morriar
reviewed
Dec 13, 2022
Contributor
Morriar
left a comment
There was a problem hiding this comment.
Very nice!
I wonder if we could add two tests under spec/tapioca/cli/gem_spec where we install different versions of Sorbet and check the output.
Something like this:
it "generates `ObjectSpace::WeakMap` as a generic type with Sorbet < X.Y.Z" do
foo = mock_gem("foo", "0.0.1") do
write("lib/foo.rb", <<~RB)
Foo = ObjectSpace::WeakMap.new
RB
end
@project.require_mock_gem(foo)
@project.require_real_gem("sorbet-static", "X.Y.Z")
@project.bundle_install
result = @project.tapioca("gem")
assert_project_file_equal("sorbet/rbi/gems/foo@0.0.1.rbi", <<~RBI)
Foo = T.let(T.unsafe(nil), ObjectSpace::WeakMap[T.untyped])
RBI
end
it "generates `ObjectSpace::WeakMap` as a non-generic type with Sorbet >= X.Y.Z" do
foo = mock_gem("foo", "0.0.1") do
write("lib/foo.rb", <<~RB)
Foo = ObjectSpace::WeakMap.new
RB
end
@project.require_mock_gem(foo)
@project.require_real_gem("sorbet-static", "X.Y.Z")
@project.bundle_install
result = @project.tapioca("gem")
assert_project_file_equal("sorbet/rbi/gems/foo@0.0.1.rbi", <<~RBI)
Foo = T.let(T.unsafe(nil), ObjectSpace::WeakMap)
RBI
end
KaanOzkan
approved these changes
Dec 14, 2022
Contributor
KaanOzkan
left a comment
There was a problem hiding this comment.
Thanks a lot for the PR and the prompt back and forth.
Morriar
approved these changes
Dec 14, 2022
Contributor
Morriar
left a comment
There was a problem hiding this comment.
Thank you for adding the other test 🙏
KaanOzkan
reviewed
Dec 14, 2022
This allows us to run a before block that sets the mock project without a strict Sorbet version dependency, and an after block to cleanup that project afterwards.
paracycle
approved these changes
Dec 14, 2022
Member
paracycle
left a comment
There was a problem hiding this comment.
Thank you! The work in this PR is very much appreciated. ❤️
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In sorbet/sorbet#6610 type_member changed from
outtofixed: T.untyped. From this point we should not pass explicitT.untypedas argument to generic type.Implementation
There is no need to special case for
ObjectSpace::WeakMapanymore.Tests
I added specs