ruby / ruby/rbs

Cannot specify type variables for `instance`

Open
#1,521 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

wontfix
Dominant language
Ruby
Stars
2.2k
Forks
256
Avg merge
6d 17h
Merged PRs (30d)
37

Description

class MyWrapper[E]
  def self.of: (E) -> instance # RBS::UnknownTypeName (it’s not inferred from `MyWrapper[E]`)
  def self.of: (E) -> instance[E] # RBS::SyntaxError
  def self.of: [E] (E) -> instance # ok, but `[E]` is not used in practice (it’s not the same `[E]` as the one in `MyWrapper[E]`)
  def self.of: (untyped) -> instance # ok, but `untyped` is bad
end

Even Steep is aware of this limitation:
https://github.com/soutaro/steep/blob/v1.5.3/lib/steep/subtyping/check.rb#L307

Proposal: instance[E]?

The problem might be significant for class as well:
https://github.com/soutaro/steep/blob/v1.5.3/lib/steep/subtyping/check.rb#L322

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed instance[E] syntax and the referenced Steep subtyping checks at lib/steep/subtyping/check.rb lines 307 and 322. Determine the intended treatment for both instance and class; done requires an agreed design and corresponding RBS and type-checking behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.