Skip to content

Support forwarding parameters in method types - #3042

Merged
soutaro merged 1 commit into
ruby:masterfrom
Shopify:support-forwarding-parameters
Aug 4, 2026
Merged

Support forwarding parameters in method types#3042
soutaro merged 1 commit into
ruby:masterfrom
Shopify:support-forwarding-parameters

Conversation

@Morriar

@Morriar Morriar commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Add parser and AST support for Ruby-style forwarding parameters in RBS method types.

def request: (...) -> Response

def logged_request: (String message, ...) -> Response

RBS already uses ... to retain existing overloads:

def foo: (Integer) -> String
       | ...

The two forms are unambiguous because forwarding appears inside a parameter list, while overload continuation appears where a method type is expected.

Implementation

Represent forwarding as an optional RBS::Types::Function::ForwardingParam node:

function.forwarding # RBS::Types::Function::ForwardingParam | nil

The node preserves the location of ... for diagnostics and syntax-aware tooling:

function.forwarding.location.source # => "..."

The change updates:

  • The C parser and generated AST
  • Native and WASM AST translation and serialization
  • Ruby types and RBS declarations
  • JSON schemas

Syntax restrictions

Forwarding must be the final parameter and may only follow required positional parameters.

Accepted:

(...) -> void
(String message, ...) -> void

Rejected:

(?String message, ...) -> void
(*String args, ...) -> void
(message: String, ...) -> void
(**String kwargs, ...) -> void
(..., String) -> void

Forwarding is also rejected in Proc and block parameter types:

^(...) -> void
() { (...) -> void } -> void

Because forwarding includes the block, an additional explicit block is rejected:

(...) { () -> void } -> void
(...) ?{ () -> void } -> void

The existing overload-continuation syntax continues to work alongside forwarding:

def foo: (...) -> void
       | ...

@Morriar
Morriar force-pushed the support-forwarding-parameters branch from d323e32 to 94176bf Compare July 28, 2026 21:26
@soutaro soutaro self-assigned this Aug 4, 2026
@soutaro
soutaro force-pushed the support-forwarding-parameters branch from 94176bf to f9f223c Compare August 4, 2026 07:30
@soutaro
soutaro added this pull request to the merge queue Aug 4, 2026
Merged via the queue into ruby:master with commit d89e4ad Aug 4, 2026
25 checks passed
@soutaro
soutaro deleted the support-forwarding-parameters branch August 4, 2026 07:48
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.

2 participants