* [ruby-core:120253] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1
@ 2024-12-15 22:30 nevans (Nicholas Evans) via ruby-core
2024-12-15 22:37 ` [ruby-core:120254] " nevans (Nicholas Evans) via ruby-core
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: nevans (Nicholas Evans) via ruby-core @ 2024-12-15 22:30 UTC (permalink / raw)
To: ruby-core; +Cc: nevans (Nicholas Evans)
Issue #20956 has been reported by nevans (Nicholas Evans).
----------------------------------------
Bug #20956: Nested alternation pattern matching bug in 3.4.0-rc1
https://bugs.ruby-lang.org/issues/20956
* Author: nevans (Nicholas Evans)
* Status: Open
* ruby -v: 3.4.0-rc1
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I think I've found a pattern matching bug in ruby 3.4.0-rc1.
```ruby
[123, ["foo"]] in [_, /\Afoo\b/i | [/\Afoo\z/i, *]]
```
I also tested this in ruby 2.7.8, with:
```ruby
case [123, ["foo"]]; in [_, /\Afoo\b/i | [/\Afoo\z/i, *]] then true; else false end
```
These return `true` in ruby 2.7.8, 3.0.7, 3.1.6, 3.2.6, and 3.3.6.
But they return false in 3.4.0-rc1.
I'm not sure if this is the best example, but it is a simplification of how I came across the bug.
Here are some other similar cases, which give the same result in 3.4.0-rc1 and 3.3.6:
```irb
irb(main):001> ["foo"] in /\Afoo\b/i | [/\Afoo\z/i, *]
=> true
irb(main):002> [123, ["foo"]] in [_, [/\Afoo\z/i, *]]
=> true
irb(main):003> [["foo"]] in [[/\Afoo\z/i, *]]
=> true
```
But this case exhibits the bug again:
```irb
irb(main):004> [["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]]
=> false
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:120254] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1
2024-12-15 22:30 [ruby-core:120253] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1 nevans (Nicholas Evans) via ruby-core
@ 2024-12-15 22:37 ` nevans (Nicholas Evans) via ruby-core
2024-12-16 18:13 ` [ruby-core:120264] " alanwu (Alan Wu) via ruby-core
2024-12-16 21:43 ` [ruby-core:120271] " eightbitraptor (Matt V-H) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: nevans (Nicholas Evans) via ruby-core @ 2024-12-15 22:37 UTC (permalink / raw)
To: ruby-core; +Cc: nevans (Nicholas Evans)
Issue #20956 has been updated by nevans (Nicholas Evans).
This would appear to be a bug in prism, or prism-adjacent code?
```console
$ ruby -e 'pp ([["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]])'
false
$ ruby --parser=parse.y -e 'pp ([["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]])'
true
```
----------------------------------------
Bug #20956: Nested alternation pattern matching bug in 3.4.0-rc1
https://bugs.ruby-lang.org/issues/20956#change-111020
* Author: nevans (Nicholas Evans)
* Status: Open
* ruby -v: 3.4.0-rc1
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I think I've found a pattern matching bug in ruby 3.4.0-rc1.
```ruby
[123, ["foo"]] in [_, /\Afoo\b/i | [/\Afoo\z/i, *]]
```
I also tested this in ruby 2.7.8, with:
```ruby
case [123, ["foo"]]; in [_, /\Afoo\b/i | [/\Afoo\z/i, *]] then true; else false end
```
These return `true` in ruby 2.7.8, 3.0.7, 3.1.6, 3.2.6, and 3.3.6.
But they return false in 3.4.0-rc1.
I'm not sure if this is the best example, but it is a simplification of how I came across the bug.
Here are some other similar cases, which give the same result in 3.4.0-rc1 and 3.3.6:
```irb
irb(main):001> ["foo"] in /\Afoo\b/i | [/\Afoo\z/i, *]
=> true
irb(main):002> [123, ["foo"]] in [_, [/\Afoo\z/i, *]]
=> true
irb(main):003> [["foo"]] in [[/\Afoo\z/i, *]]
=> true
```
But this case exhibits the bug again:
```irb
irb(main):004> [["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]]
=> false
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:120264] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1
2024-12-15 22:30 [ruby-core:120253] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1 nevans (Nicholas Evans) via ruby-core
2024-12-15 22:37 ` [ruby-core:120254] " nevans (Nicholas Evans) via ruby-core
@ 2024-12-16 18:13 ` alanwu (Alan Wu) via ruby-core
2024-12-16 21:43 ` [ruby-core:120271] " eightbitraptor (Matt V-H) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: alanwu (Alan Wu) via ruby-core @ 2024-12-16 18:13 UTC (permalink / raw)
To: ruby-core; +Cc: alanwu (Alan Wu)
Issue #20956 has been updated by alanwu (Alan Wu).
Assignee set to prism
----------------------------------------
Bug #20956: Nested alternation pattern matching bug in 3.4.0-rc1
https://bugs.ruby-lang.org/issues/20956#change-111031
* Author: nevans (Nicholas Evans)
* Status: Open
* Assignee: prism
* ruby -v: 3.4.0-rc1
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I think I've found a pattern matching bug in ruby 3.4.0-rc1.
```ruby
[123, ["foo"]] in [_, /\Afoo\b/i | [/\Afoo\z/i, *]]
```
I also tested this in ruby 2.7.8, with:
```ruby
case [123, ["foo"]]; in [_, /\Afoo\b/i | [/\Afoo\z/i, *]] then true; else false end
```
These return `true` in ruby 2.7.8, 3.0.7, 3.1.6, 3.2.6, and 3.3.6.
But they return false in 3.4.0-rc1.
I'm not sure if this is the best example, but it is a simplification of how I came across the bug.
Here are some other similar cases, which give the same result in 3.4.0-rc1 and 3.3.6:
```irb
irb(main):001> ["foo"] in /\Afoo\b/i | [/\Afoo\z/i, *]
=> true
irb(main):002> [123, ["foo"]] in [_, [/\Afoo\z/i, *]]
=> true
irb(main):003> [["foo"]] in [[/\Afoo\z/i, *]]
=> true
```
But this case exhibits the bug again:
```irb
irb(main):004> [["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]]
=> false
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
* [ruby-core:120271] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1
2024-12-15 22:30 [ruby-core:120253] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1 nevans (Nicholas Evans) via ruby-core
2024-12-15 22:37 ` [ruby-core:120254] " nevans (Nicholas Evans) via ruby-core
2024-12-16 18:13 ` [ruby-core:120264] " alanwu (Alan Wu) via ruby-core
@ 2024-12-16 21:43 ` eightbitraptor (Matt V-H) via ruby-core
2 siblings, 0 replies; 4+ messages in thread
From: eightbitraptor (Matt V-H) via ruby-core @ 2024-12-16 21:43 UTC (permalink / raw)
To: ruby-core; +Cc: eightbitraptor (Matt V-H)
Issue #20956 has been updated by eightbitraptor (Matt V-H).
This does appear to be an issue in `prism_compile.c`
Golfed down to
```ruby
1 in [1 | [1]]
```
The instructions generated by Prism and parse.y are pretty significantly different, and appears to be related to nesting an `Alternative Pattern` inside an `Array Pattern`
generated instructions and diff output [is in this gist](https://gist.github.com/eightbitraptor/b405199234393e1466c19ccb46a53877)
----------------------------------------
Bug #20956: Nested alternation pattern matching bug in 3.4.0-rc1
https://bugs.ruby-lang.org/issues/20956#change-111038
* Author: nevans (Nicholas Evans)
* Status: Open
* Assignee: prism
* ruby -v: 3.4.0-rc1
* Backport: 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN
----------------------------------------
I think I've found a pattern matching bug in ruby 3.4.0-rc1.
```ruby
[123, ["foo"]] in [_, /\Afoo\b/i | [/\Afoo\z/i, *]]
```
I also tested this in ruby 2.7.8, with:
```ruby
case [123, ["foo"]]; in [_, /\Afoo\b/i | [/\Afoo\z/i, *]] then true; else false end
```
These return `true` in ruby 2.7.8, 3.0.7, 3.1.6, 3.2.6, and 3.3.6.
But they return false in 3.4.0-rc1.
I'm not sure if this is the best example, but it is a simplification of how I came across the bug.
Here are some other similar cases, which give the same result in 3.4.0-rc1 and 3.3.6:
```irb
irb(main):001> ["foo"] in /\Afoo\b/i | [/\Afoo\z/i, *]
=> true
irb(main):002> [123, ["foo"]] in [_, [/\Afoo\z/i, *]]
=> true
irb(main):003> [["foo"]] in [[/\Afoo\z/i, *]]
=> true
```
But this case exhibits the bug again:
```irb
irb(main):004> [["foo"]] in [/\Afoo\b/i | [/\Afoo\z/i, *]]
=> false
```
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-12-16 21:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-15 22:30 [ruby-core:120253] [Ruby master Bug#20956] Nested alternation pattern matching bug in 3.4.0-rc1 nevans (Nicholas Evans) via ruby-core
2024-12-15 22:37 ` [ruby-core:120254] " nevans (Nicholas Evans) via ruby-core
2024-12-16 18:13 ` [ruby-core:120264] " alanwu (Alan Wu) via ruby-core
2024-12-16 21:43 ` [ruby-core:120271] " eightbitraptor (Matt V-H) via ruby-core
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 NNTP newsgroup(s).