Issue #16838 has been updated by shan (Shannon Skipper).


After I filed this, al203-cr on #ruby IRC pointed out this seems intentional since `rb_undef_alloc_func(rb_cArithSeq);` is manually undefined here: https://github.com/ruby/ruby/blob/v2_7_1/enumerator.c#L4068

Treating it as immutable makes sense to me, since an ArithmeticSequence's begin/end/exclude_end?/step can't be mutated without Fiddle. It just surprised me, since they're not frozen.

``` ruby
1.step.frozen?
#=> false
```

Should an ArithmeticSequence be frozen or cloneable?

----------------------------------------
Bug #16838: Enumerator::ArithmeticSequence missing allocator for #clone and #dup
https://bugs.ruby-lang.org/issues/16838#change-85429

* Author: shan (Shannon Skipper)
* Status: Open
* Priority: Normal
* ruby -v: ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
In Ruby 2.5, with an Enumerator:

``` ruby
1.step.clone
#=> Enumerator
```

In Ruby 2.6, with an Enumerator::ArithmeticSequence:

``` ruby
1.step.clone
#!> TypeError (allocator undefined for Enumerator::ArithmeticSequence)
```

I've gotten around it in 2.6 and 2.7 by checking if an enum is an ArithmeticSequence and reconstituting a new one if so:

``` ruby
Range.new(enum.begin, enum.end, enum.exclude_end?) % enum.step
```

Instead of cloning:

```ruby
enum.clone
```

I filed this as a bug rather than feature, since it seemed like a breaking change and I wasn't sure if it was intentional. Thank you!




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