Support a lambda pattern - #485
Open
sinsoku wants to merge 1 commit into
Open
Conversation
`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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation / Background
This Pull Request has been created because a lambda pattern aborts the analysis:
in ->(x) { ... }is a valid pattern that matches by===, butAST.create_pattern_nodehad no branch for:lambda_node. ruby/ruby uses one intest/ruby/test_pattern_matching.rbandspec/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