ml.ruby-lang.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

ruby-dev

Thread Start a new thread
Download
Threads by month
  • ----- 2025 -----
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
ruby-dev@ml.ruby-lang.org

June 2025

  • 1 participants
  • 1 discussions
[ruby-dev:52159] [Ruby Feature#21393] One-line pattern matching syntax as a method argument
by koic (Koichi ITO) 02 Jun '25

02 Jun '25
Issue #21393 has been reported by koic (Koichi ITO). ---------------------------------------- Feature #21393: One-line pattern matching syntax as a method argument https://bugs.ruby-lang.org/issues/21393 * Author: koic (Koichi ITO) * Status: Open ---------------------------------------- ## Context Using one-line `in` pattern matching syntax as a method argument causes a syntax error. ```console $ ruby -vce 'do_something(expression in pattern)' ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin24] ruby: -e:1: syntax errors found (SyntaxError) > 1 | do_something(expression in pattern) | ^~ unexpected 'in'; expected a `)` to close the arguments | ^ unexpected ')', ignoring it | ^ unexpected ')', expecting end-of-input ``` Wrapping the argument in parentheses avoids the syntax error: ```console $ ruby -vce 'do_something((expression in pattern))' ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin24] Syntax OK ``` This was unexpected, as I assumed `do_something(expression in pattern)` would work without parentheses. For reference, `do_something(expression => pattern)`, which results in a void context, is valid syntax. ```console $ ruby -vce 'do_something(expression => pattern)' ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin24] Syntax OK ``` ## Proposal It seems more appropriate that `do_something(expression in pattern)` should also be valid syntax. ## Additional Information This behavior is consistent not only in Prism, but also in `parse.y`. ```console $ ruby --parser=parse.y -vce 'do_something(expression in pattern)' ruby 3.4.4 (2025-05-14 revision a38531fd3f) [x86_64-darwin24] -e:1: syntax error, unexpected 'in', expecting ')' do_something(expression in pattern) ruby: compile error (SyntaxError) ``` I encountered this while working on a RuboCop issue: https://github.com/rubocop/rubocop/issues/14217 -- https://bugs.ruby-lang.org/
2 2
0 0

HyperKitty Powered by HyperKitty version 1.3.12.