Add type arguments support to singleton types#46
Open
Conversation
st0012
reviewed
May 20, 2025
46c9aa2 to
91eafe8
Compare
This is a Follow-up to ruby#2590
Co-authored-by: Soutaro Matsumoto <matsumoto@soutaro.com>
rbs v3 does not have a type definition for `ruby2_keywords`, so it cannot pass type checking. We will apply a patch to address this, expecting the type to be added in rbs v4.
this adds hash-like typing to signal its key-value store semantics. it seems like a breaking change, but in practice this has been broken for a while. Other wrong sigs were fixed, such as transaction, which requires a block.
The current signature requires all three positional arguments:
def initialize: (_Writer io, Integer level, Integer strategy, **untyped opts) -> void
However, the Ruby documentation and actual C implementation show that
both level and strategy have default values (nil), making them optional:
Zlib::GzipWriter.new(io, level = nil, strategy = nil, options = {})
The documentation examples also demonstrate calling with just io:
File.open('hoge.gz', 'w') do |f|
gz = Zlib::GzipWriter.new(f)
gz.write 'jugemu jugemu gokou no surikire...'
gz.close
end
This change updates the signature to allow 1-4 arguments by making
level and strategy optional nilable parameters:
def initialize: (_Writer io, ?Integer? level, ?Integer? strategy, **untyped opts) -> void
This matches the actual Ruby behavior and resolves false positive type
errors when calling GzipWriter.new with fewer than three arguments.
[rbs/test] Check type arguments size
This allows manual execution of Valgrind tests on any branch via GitHub Actions UI.
Add workflow_dispatch trigger to Valgrind workflow
Bumps [actions/cache](https://github.com/actions/cache) from 4 to 5. - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](actions/cache@v4...v5) --- updated-dependencies: - dependency-name: actions/cache dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com>
Add crate metadata
Crates 0.1.1
bundle update (2026-02-03)
Use unreleased steep for `rake typecheck_test`
Fix for string reference corruption issue
Fix CI for cargo:lint
Drop valgrind
by RBS/Layout/OverloadIndentation
Update rubocop-on-rbs to v1.9.1
Morriar
reviewed
Feb 11, 2026
bundle update (2026-02-10)
…iting-and-exceptions [Kernel] Add tests for Exiting and Exception functions
…transform_keys!` `#transform_keys` accepts an optional positional argument for mapping keys, which can be combined with a block.
doc: fixes some typos in core/string.rbs
Add variants with positional argument to `Hash#transform_keys`
Previously, singleton type arguments could not be supported by RBS. This adds support for them, enabling syntax like `singleton(Array)[String, Integer]`.
91eafe8 to
980f386
Compare
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.
ticket: https://github.com/Shopify/team-ruby-dx/issues/1460
Add support for parameterized singleton types
This PR adds support for type parameters on singleton types to match the functionality available in Sorbet's
T.class_of(X)[Y]syntax. With this change, RBS now supports the equivalent syntax:singleton(X)[Y].Changes
Examples
Previously, only this was supported:
Now this is also supported:
Questions
Should the
Applicationmodule be included in theClassSingletonclass, similar to how it's included inClassInstanceandInterface? Currently, I've implemented the necessary methods directly.Are there additional methods such as
map_typeandeach_typethat should be added to theClassSingletonclass?