Skip to content

Share reflected method parameter compilation - #2689

Open
Morriar wants to merge 1 commit into
mainfrom
at/share-method-parameter-compilation
Open

Share reflected method parameter compilation#2689
Morriar wants to merge 1 commit into
mainfrom
at/share-method-parameter-compilation

Conversation

@Morriar

@Morriar Morriar commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Centralize reflected parameter name sanitization and RBI::Param construction in RBIHelper and reuse the helper from DSL and gem method compilation.

@Morriar
Morriar requested a review from a team as a code owner July 30, 2026 21:25
@Morriar Morriar added the chore label Jul 30, 2026
when :block
RBI::BlockParam.new(name)
else
Kernel.raise "Unknown type `#{type}`."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL, agent found that :nokey is a valid parameter kind for: def foo(*args, **nil). Apparently it's used to reject kwargs. It's not supported in rbi but Sorbet doesn't support it either so not raising might be enough.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will also be a :noblock version of it in Ruby 4.1: ruby/ruby@9967418

def foo(*args, &nil) = 42

method(:foo).parameters # => [[:rest, :args], [:noblock]]

@paracycle paracycle left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactor, thank you!

Comment on lines +106 to +108
fallback_name = "_arg#{index}"
name ||= fallback_name
name = fallback_name unless valid_parameter_name?(name)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems we are allocating a fallback_name unnecessarily for each parameter here. Can we also refactor valid_parameter_name? to accept a String? and reject nil values, so that we can do:

Suggested change
fallback_name = "_arg#{index}"
name ||= fallback_name
name = fallback_name unless valid_parameter_name?(name)
name = "_arg#{index}" unless valid_parameter_name?(name)

This way the new string allocation will only happen for invalid or missing parameter names

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants