Skip to content

Add type arguments support to singleton types#46

Open
allcre wants to merge 112 commits intomasterfrom
Add_type_arguments_support_to_singleton_types
Open

Add type arguments support to singleton types#46
allcre wants to merge 112 commits intomasterfrom
Add_type_arguments_support_to_singleton_types

Conversation

@allcre
Copy link

@allcre allcre commented May 20, 2025

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

  • Updated the RBS grammar to allow type arguments for singleton types
  • Modified the C parser implementation to accept type parameters for singleton types

Examples

Previously, only this was supported:

singleton(Array)   # Class singleton type with no type parameters

Now this is also supported:

singleton(Array)[String]   # Class singleton type with String type parameter

Questions

  1. Should the Application module be included in the ClassSingleton class, similar to how it's included in ClassInstance and Interface? Currently, I've implemented the necessary methods directly.

  2. Are there additional methods such as map_type and each_type that should be added to the ClassSingleton class?

@allcre allcre force-pushed the Add_type_arguments_support_to_singleton_types branch 6 times, most recently from 46c9aa2 to 91eafe8 Compare May 21, 2025 15:53
@allcre allcre requested review from Morriar, amomchilov and st0012 May 21, 2025 15:56
@allcre allcre marked this pull request as ready for review May 21, 2025 16:00
ksss and others added 19 commits August 8, 2025 16:11
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>
soutaro and others added 10 commits February 12, 2026 10:54
…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]`.
@soutaro soutaro force-pushed the Add_type_arguments_support_to_singleton_types branch from 91eafe8 to 980f386 Compare February 16, 2026 06:15
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.