Skip to content

Accept classes for RBS singleton(X) parameters - #364

Closed
apiology wants to merge 2 commits into
masterfrom
translate-rbs-singleton-to-class
Closed

apiology wants to merge 2 commits into
masterfrom
translate-rbs-singleton-to-class

Conversation

@apiology

@apiology apiology commented Oct 28, 2026 •

Copy link
Copy Markdown
Owner

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem:

In RBS, singleton(X) is the type of the class object X itself (or a subclass), not of its instances.

Passing a class to an RBS singleton(...) parameter is rejected:

class Resource; end
class Task < Resource; end
class Collection
  #: (type: singleton(Resource)) -> void
  def initialize(type:); end
end
# Wrong argument type for Collection.new: type expected Resource, received Class<Task>
Collection.new(type: Task)

Any gem RBS declaring singleton(X) reports correct calls as errors, while an instance passed there goes unflagged; responders' RBS types ActionController::Base.responders as singleton(ActionController::Responder), which Solargraph reads as a Responder instance.

Solution:

Translate RBS singleton(X) to Class<X> instead of the instance type X, so class arguments conform and calls on a singleton(X) result resolve to class methods.

RbsTranslator mapped singleton(X) to the instance type X, so a
parameter declared singleton(Resource) rejected a class argument
(received Class<Task>) and accepted an instance instead. Translate it
to Class<X>, which Solargraph already resolves to X's class methods.
apiology added a commit that referenced this pull request Nov 17, 2026
singleton(X) is the class object, but the translator produced an
instance of X: passing a subclass where RBS expects singleton(X)
was reported as a wrong argument type, and passing an instance was
accepted.

Carried over from #364.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LTpguHxFEQL9KJ7MGedKby
@apiology

Copy link
Copy Markdown
Owner Author

Claude: Moved into castwide/solargraph#1104, which now translates singleton(X) to Class<X> with these specs.

@apiology apiology closed this Nov 17, 2026
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.

1 participant