📚

[Feature #21393] メソッドの引数に1行パターンマッチを渡すとシンタックスエラーになるというバグ報告

に公開

[Feature #21393] One-line pattern matching syntax as a method argument

  • 次のようにメソッドの引数に1行パターンマッチを渡すとシンタックスエラーになるというバグ報告
$ 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
  • これは () が2重だとエラーにならない
$ ruby -vce 'do_something((expression in pattern))'
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin24]
Syntax OK
  • また => の場合でも有効なシンタックスとして扱われる
$ ruby -vce 'do_something(expression => pattern)'
ruby 3.4.4 (2025-05-14 revision a38531fd3f) +PRISM [x86_64-darwin24]
Syntax OK
  • これなんですがこれを許容した場合に
do_something(expr in a, b, c)
  • という構文が
do_something((expr in a), b, c)
  • なのか
do_something((expr in [a, b, c]))
GitHubで編集を提案

Discussion