rbs icon indicating copy to clipboard operation
rbs copied to clipboard

Untyped block args

Open soutaro opened this issue 1 year ago • 2 comments

AR::Base.scope accepts lambdas, but the type of the lambdas is difficult to describe in RBS.

class AR::Base
  def self.scope: (Symbol, ^(*untyped, **untyped) -> void) -> void
end

The proc type means it can receive any argument and any keywords, while what we want is a proc is required but the type of its arguments is not checked. So, we want to introduce a new syntax for untyped args.

Possible syntax:

class AR::Base
  # ...
  def self.scope: (Symbol, ^(...) -> void) -> void
                | (Symbol) { (...) -> void } -> void

  # ?
  def self.scope: (Symbol, ^(?) -> void) -> void
                | (Symbol) { (?) -> void } -> void

  # untyped
  def self.scope: (Symbol, ^untyped -> void) -> void
                | (Symbol) { untyped -> void } -> void
end

Any other ones?

soutaro avatar May 16 '23 07:05 soutaro

Can simply use Proc for lambdas; this new syntax mainly benefits untyped blocks

untyped -> void

This suggestion is uncomfortably similar to (untyped) -> void. In fact, it conflicts with the possibility of making arguments’ round parentheses optional (if there’s such a possibility).

ParadoxV5 avatar Jun 04 '23 16:06 ParadoxV5

I'm going to implement it in (?) -> void syntax. ... would be confusing because Ruby has similar syntax with totally different semantics. untyped -> void is too similar to normal positional argument.

soutaro avatar Jun 06 '23 17:06 soutaro