* [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
@ 2022-09-30 22:03 baweaver (Brandon Weaver)
2022-09-30 22:08 ` [ruby-core:110155] " baweaver (Brandon Weaver)
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: baweaver (Brandon Weaver) @ 2022-09-30 22:03 UTC (permalink / raw)
To: ruby-core
Issue #19033 has been reported by baweaver (Brandon Weaver).
----------------------------------------
Bug #19033: One-liner pattern match as Boolean arg syntax error
https://bugs.ruby-lang.org/issues/19033
* Author: baweaver (Brandon Weaver)
* Status: Open
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:110155] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
@ 2022-09-30 22:08 ` baweaver (Brandon Weaver)
2022-09-30 22:45 ` [ruby-core:110156] " jeremyevans0 (Jeremy Evans)
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: baweaver (Brandon Weaver) @ 2022-09-30 22:08 UTC (permalink / raw)
To: ruby-core
Issue #19033 has been updated by baweaver (Brandon Weaver).
Addendum: We did find that `expect((value in pattern))` works, but not `expect(value in pattern)`, which is where we find things to be confusing
----------------------------------------
Bug #19033: One-liner pattern match as Boolean arg syntax error
https://bugs.ruby-lang.org/issues/19033#change-99412
* Author: baweaver (Brandon Weaver)
* Status: Open
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:110156] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
2022-09-30 22:08 ` [ruby-core:110155] " baweaver (Brandon Weaver)
@ 2022-09-30 22:45 ` jeremyevans0 (Jeremy Evans)
2022-10-03 13:58 ` [ruby-core:110171] " Dan0042 (Daniel DeLorme)
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-09-30 22:45 UTC (permalink / raw)
To: ruby-core
Issue #19033 has been updated by jeremyevans0 (Jeremy Evans).
Regarding `expect(value in pattern)`, I think it is expected that is a syntax error. This is how Ruby has always worked for `expect(true if true)`, which is invalid syntax (`expect((true if true))` is valid syntax).
In regards to `expect value in pattern`, the syntax is a ambiguous. I would assume if it was supported at all, it would be parsed as `expect(value) in pattern`, not as `expect(value in pattern)`. I think it's best for it to remain a syntax error.
----------------------------------------
Bug #19033: One-liner pattern match as Boolean arg syntax error
https://bugs.ruby-lang.org/issues/19033#change-99413
* Author: baweaver (Brandon Weaver)
* Status: Open
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:110171] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
2022-09-30 22:08 ` [ruby-core:110155] " baweaver (Brandon Weaver)
2022-09-30 22:45 ` [ruby-core:110156] " jeremyevans0 (Jeremy Evans)
@ 2022-10-03 13:58 ` Dan0042 (Daniel DeLorme)
2022-10-20 4:16 ` [ruby-core:110427] " matz (Yukihiro Matsumoto)
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Dan0042 (Daniel DeLorme) @ 2022-10-03 13:58 UTC (permalink / raw)
To: ruby-core
Issue #19033 has been updated by Dan0042 (Daniel DeLorme).
`expect value in pattern` is a syntax error, but
`expect value if pattern` is parsed as `expect(value) if pattern`
I wonder why the difference?
----------------------------------------
Bug #19033: One-liner pattern match as Boolean arg syntax error
https://bugs.ruby-lang.org/issues/19033#change-99444
* Author: baweaver (Brandon Weaver)
* Status: Open
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:110427] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
` (2 preceding siblings ...)
2022-10-03 13:58 ` [ruby-core:110171] " Dan0042 (Daniel DeLorme)
@ 2022-10-20 4:16 ` matz (Yukihiro Matsumoto)
2022-10-20 5:28 ` [ruby-core:110429] " mame (Yusuke Endoh)
2022-10-20 5:30 ` [ruby-core:110430] " baweaver (Brandon Weaver)
5 siblings, 0 replies; 7+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-10-20 4:16 UTC (permalink / raw)
To: ruby-core
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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:110429] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
` (3 preceding siblings ...)
2022-10-20 4:16 ` [ruby-core:110427] " matz (Yukihiro Matsumoto)
@ 2022-10-20 5:28 ` mame (Yusuke Endoh)
2022-10-20 5:30 ` [ruby-core:110430] " baweaver (Brandon Weaver)
5 siblings, 0 replies; 7+ messages in thread
From: mame (Yusuke Endoh) @ 2022-10-20 5:28 UTC (permalink / raw)
To: ruby-core
Issue #19033 has been updated by mame (Yusuke Endoh).
Note that `foo(1, 2, 3 in ary)` could be inherently ambiguous. It can be interpreted as `foo((1, 2, 3 in ary))` or `foo(1, 2, (3 in ary))`.
----------------------------------------
Bug #19033: One-liner pattern match as Boolean arg syntax error
https://bugs.ruby-lang.org/issues/19033#change-99739
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
* [ruby-core:110430] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
` (4 preceding siblings ...)
2022-10-20 5:28 ` [ruby-core:110429] " mame (Yusuke Endoh)
@ 2022-10-20 5:30 ` baweaver (Brandon Weaver)
5 siblings, 0 replies; 7+ messages in thread
From: baweaver (Brandon Weaver) @ 2022-10-20 5:30 UTC (permalink / raw)
To: ruby-core
Issue #19033 has been updated by baweaver (Brandon Weaver).
mame (Yusuke Endoh) wrote in #note-6:
> Note that `foo(1, 2, 3 in ary)` could be inherently ambiguous. It can be interpreted as `foo((1, 2, 3 in ary))` or `foo(1, 2, (3 in ary))`.
Agreed, these are difficult edge cases, and trying to make the parser work with them would be challenging.
----------------------------------------
Bug #19033: One-liner pattern match as Boolean arg syntax error
https://bugs.ruby-lang.org/issues/19033#change-99740
* 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/
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-10-20 5:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-30 22:03 [ruby-core:110154] [Ruby master Bug#19033] One-liner pattern match as Boolean arg syntax error baweaver (Brandon Weaver)
2022-09-30 22:08 ` [ruby-core:110155] " baweaver (Brandon Weaver)
2022-09-30 22:45 ` [ruby-core:110156] " jeremyevans0 (Jeremy Evans)
2022-10-03 13:58 ` [ruby-core:110171] " Dan0042 (Daniel DeLorme)
2022-10-20 4:16 ` [ruby-core:110427] " matz (Yukihiro Matsumoto)
2022-10-20 5:28 ` [ruby-core:110429] " mame (Yusuke Endoh)
2022-10-20 5:30 ` [ruby-core:110430] " baweaver (Brandon Weaver)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).