Issue #17534 has been updated by palkan (Vladimir Dementyev).


So, what I found: the bug is caused by `iseq_peephole_optimize` and find patterns iseq incompatibility; `remove_unreachable_chunk` doesn't remove `while_begin`, `next_loop` and other find_pattern specific labels, but removes general pattern matching instructions (including stack allocation for "local" variables). (Disabling `remove_unreachable_chunk` fixes this).

Possibly, that happens due to the labels cycle (`while_begin` -> `next_loop` -> `while_begin`); though I'm not really familiar with the _peephole optimization_. /cc @nobu @ko1

----------------------------------------
Bug #17534: Pattern-matching is broken with find pattern
https://bugs.ruby-lang.org/issues/17534#change-89995

* Author: zverok (Victor Shepelev)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
The minimal reproduction code:

```ruby
case [1, 2, 3]
in y
  puts "branch1"
in [*, x, *]
  puts "branch2"
else
  puts "branch3"
end
```
This outputs long "raw disasm" sequence, and then
```
---------------------
break_pm.rb:6: argument stack underflow (-1)
break_pm.rb: compile error (SyntaxError)
```

```
$ ruby -v
ruby 3.1.0dev (2021-01-13T09:12:49Z master 6f6dfdcc68) [x86_64-linux]
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>