From: sto.mar@... Date: 2017-02-20T20:52:46+00:00 Subject: [ruby-core:79636] [Ruby trunk Bug#13237] Behavior for #dup and #clone on Rational/Complex/BigDecimal differs from Integer/Float Issue #13237 has been reported by Marcus Stollsteimer. ---------------------------------------- Bug #13237: Behavior for #dup and #clone on Rational/Complex/BigDecimal differs from Integer/Float https://bugs.ruby-lang.org/issues/13237 * Author: Marcus Stollsteimer * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-linux] * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- Since the implementation of feature #12979, #dup and #clone on Integer and Float do not raise a `TypeError` anymore, and silently return self. Rational and Complex still raise an exception. I'm not sure whether this inconsistent behavior is intended or only an oversight. I guess all Numeric classes should behave in a similar way? Additionally, what is the intention regarding the returned object for non-immediate numeric values, should they return self or a new object? At the time being, BigDecimal (which already did allow #dup/#clone before the change) returns a new object, while Bignum integers return self. Current behavior: ``` ruby RUBY_VERSION # => "2.4.0" 1.dup # => 1 1.clone # => 1 1.5.dup # => 1.5 1.5.clone # => 1.5 Rational(1).dup rescue $! # => # Rational(1).clone rescue $! # => # Complex(1).dup rescue $! # => # Complex(1).clone rescue $! # => # require "bigdecimal" BigDecimal(1).dup # => 0.1e1 BigDecimal(1).clone # => 0.1e1 d = (1<<64) [d.object_id, d.dup.object_id, d.clone.object_id] # => [5134140, 5134140, 5134140] d = BigDecimal(1) [d.object_id, d.dup.object_id, d.clone.object_id] # => [5133040, 5132900, 5132840] ``` Old behavior: ``` ruby RUBY_VERSION # => "2.3.3" 1.dup rescue $! # => # 1.clone rescue $! # => # 1.5.dup rescue $! # => # 1.5.clone rescue $! # => # Rational(1).dup rescue $! # => # Rational(1).clone rescue $! # => # Complex(1).dup rescue $! # => # Complex(1).clone rescue $! # => # require "bigdecimal" BigDecimal(1).dup # => # BigDecimal(1).clone # => # ``` -- https://bugs.ruby-lang.org/ Unsubscribe: