Issue #17092 has been reported by marcandre (Marc-Andre Lafortune).

----------------------------------------
Bug #17092: Array#flatten with finite depth should flatten recursive arrays
https://bugs.ruby-lang.org/issues/17092

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: REQUIRED
----------------------------------------
Recursive arrays can not be flattened currently:

```ruby
a = []; a << a
a.flatten(2) # => tried to flatten recursive array
```

The only valid reason to raise an error for recursive arrays is for flatten with no argument (or negative argument); the case for finite-depth flatten is not problematic.

This fix has the bonus of speeding up the finite-depth case in general.

I will merge https://github.com/ruby/ruby/pull/3374, @nobu asked for backports.



-- 
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>