Skip to content
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

"singleton(class with this mixin)" is not supported #1715

Open
HoneyryderChuck opened this issue Jan 9, 2024 · 0 comments
Open

"singleton(class with this mixin)" is not supported #1715

HoneyryderChuck opened this issue Jan 9, 2024 · 0 comments

Comments

@HoneyryderChuck
Copy link
Contributor

Currently, the usage of singleton seems to be limited to the following usages:

# foo accepts the FooClass as argument, or any subclass of it
# rb: foo(FooClass)
def foo: (singleton(FooClass))

# foo accepts the FooModule module as argument
# rb: foo(FooModule)
def foo: (singleton(FooModule))

# foo accepts instances of a class with the FooModule mixed in, or with its singleton class extended by it
# rb: foo(foo_class_instance)
def foo: (FooModule)

Currently, it seems to not be possible to declare the acceptance of "the class with FooModule mixed in", for functions called with foo(ClassWithFooModule). I've tried declaring. foo: (Object & FooModule), but this is something which the parser does not accept:

 Syntax error: expected a token `pRPAREN`, token=`&` (pAMP) (RBS::ParsingError)

      def foo: (singleton(Object & Job)) -> void

In lack of an alternative way to declare it, I guess this makes it a feature request. I think this is a quite common pattern, for instance in background job frameworks, such as sidekiq or shoryuken, where you can call Sidekiq.enqueue(JobClass) or pass it to push_bulk, and the JobClass only has to include the Sidekiq::Job mixin (shoryuken works similarly), or in middleware chains, which usually contain classes as arguments, and in some cases these must include some some module, or "quack" like some interface (usually via implementing call(this, that, other)).

(the latter point points to also supporting this pattern for interfaces, i.e. singleton(Object & _IFoo))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant