Skip to content

Pass the subject to a lambda pattern - #496

Merged
mame merged 2 commits into
ruby:masterfrom
mame:fix-lambda-pattern-subject
Sep 28, 2026
Merged

mame merged 2 commits into
ruby:masterfrom
mame:fix-lambda-pattern-subject

Conversation

@mame

@mame mame commented Sep 28, 2026

Copy link
Copy Markdown
Member

Follow-up to #485, which stopped the crash but left the subject unused.

in ->(x) { ... } matches by calling the lambda with ===, but the lambda parameter stayed untyped. Now that a lambda call binds its arguments like a method's (#481), this calls === with the subject:

case 0
in ->(i) { i.foo }   # now: undefined method: Integer#foo
end

A wrong arity is reported, as Ruby raises ArgumentError for it.

mame and others added 2 commits September 28, 2026 20:01
`in ->(x) { ... }` matches by calling the lambda with `===`, but the
lambda pattern was installed as a plain expression, so its parameter
stayed untyped and nothing in the body was checked against the matched
value. Call `===` on it with the subject, which binds the parameters now
that a lambda call binds like a method's.

A wrong arity is reported, as Ruby raises ArgumentError for it. The
diagnostic reads mid_code_range from the node, which LambdaNode now
answers with nil so that it points at the whole lambda.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mame
mame enabled auto-merge (rebase) September 28, 2026 16:59
@mame
mame merged commit d8373fc into ruby:master Sep 28, 2026
6 checks passed
@mame
mame deleted the fix-lambda-pattern-subject branch September 28, 2026 17:01
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