From: "matz (Yukihiro Matsumoto)" Date: 2022-10-20T04:16:42+00:00 Subject: [ruby-core:110427] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error Issue #19033 has been updated by matz (Yukihiro Matsumoto). Status changed from Open to Rejected I can understand the feeling the `a in b` should be accepted as an argument expression. But in reality, it needs huge effort to modify the parser. I don't think it worth both cost and complexity. If someone comes up with the pull-request, we will reconsider. Matz. ---------------------------------------- Bug #19033: One-liner pattern match as Boolean arg syntax error https://bugs.ruby-lang.org/issues/19033#change-99737 * Author: baweaver (Brandon Weaver) * Status: Rejected * Priority: Normal * ruby -v: 3.0.2 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- I was chatting earlier with Seb Wilgosz about pattern matching in tests, and suggested that he might consider the following: ```ruby expect result in pattern ``` ...but he reported back this will syntax error, including with parens: ```ruby res = [:not_found, 999] expect(res in [:not_found, *payload]) # => SyntaxError: # /spec/app/interactors/articles/publish_spec.rb:13: syntax error, unexpected `in', expecting ')' ``` Interestingly though the following work: ```ruby res = [:not_found, 999] expect(res) in([:not_found, *payload]) # 1 example, 0 failures expect(res) in([:not_found, 1, 3]) # 1 example, 0 failures ``` While this appears like an RSpec issue I would contend that it is reproducible with any other method that takes a boolean-like argument. For me this feels like a syntax bug, but could see a case where it may be interpreted as ambiguous depending on the precedence of `in` relative to method arguments much like `method_name value if condition` is vague between `method_name(value) if condition` and `method_name(value if condition)`. That'll be especially difficult if it's `method_name value in pattern if condition`, so I do not envy parser writers here. Would be curious for thoughts on that, or if we're looking at that wrong. -- https://bugs.ruby-lang.org/ Unsubscribe: