-
Notifications
You must be signed in to change notification settings - Fork 125
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
Do not pass T.untyped
to ObjectSpace::WeakMap
#1303
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
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.
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.
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
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.
Thanks a lot for the PR and the prompt back and forth.
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.
Thank you for adding the other test 🙏
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.
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.
Thank you! The work in this PR is very much appreciated. ❤️
Motivation
In sorbet/sorbet#6610 type_member changed from
out
tofixed: T.untyped
. From this point we should not pass explicitT.untyped
as argument to generic type.Implementation
There is no need to special case for
ObjectSpace::WeakMap
anymore.Tests
I added specs