Skip to content

Support a lambda pattern - #485

Open
sinsoku wants to merge 1 commit into
ruby:masterfrom
sinsoku:support-lambda-pattern
Open

Support a lambda pattern#485
sinsoku wants to merge 1 commit into
ruby:masterfrom
sinsoku:support-lambda-pattern

Conversation

@sinsoku

@sinsoku sinsoku commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator

Motivation / Background

This Pull Request has been created because a lambda pattern aborts the analysis:

case 0
in ->(i) { i == 0 }
end
#=> unknown pattern node type: lambda_node (RuntimeError)

in ->(x) { ... } is a valid pattern that matches by ===, but AST.create_pattern_node had no branch for :lambda_node. ruby/ruby uses one in test/ruby/test_pattern_matching.rb and spec/ruby/language/pattern_matching_spec.rb.

Detail

TypeProf does not pass the subject to the lambda, so its parameter stays untyped and the body is not checked against the matched value. This Pull Request only stops the crash.

🤖 Generated with Claude Code

`in ->(x) { ... }` matches by `===`, but AST.create_pattern_node had no
branch for :lambda_node and raised "unknown pattern node type:
lambda_node". Route it through the same install_pattern0 path as the
other value patterns; CaseMatchNode#install0 discards the pattern's
return value, so returning a proc instead of the subject is harmless.
The subject is not passed to the lambda, so its parameter stays untyped
and the body is not checked against the matched value.
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