Bug #4559

Proc#== does not match the documented behaviour

Added by Adam Prescott about 3 years ago. Updated over 1 year ago.

[ruby-core:35632]
Status:Closed
Priority:Low
Assignee:Koichi Sasada
Category:core
Target version:2.0.0
ruby -v:ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux] Backport:

Description

=begin
To see a paste concisely showing the problem, see https://gist.github.com/899026/ba84d66b02727675320dc4f031637d753a41c209

Code is shown below for 1.9.2p180.

The documented behaviour (and my own expectation for (({#==}))) is: "Return true if prc is the same object as other_proc, or if they are both procs with the same body."

RUBY_DESCRIPTION #=> ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]

proc { 1 } == proc { 1 } # => true
proc { 1 + 1 } == proc { 1 + 1 } # => false

proc { |x| x } == proc { |x| x } # => true
proc { |x| x.foo } == proc { |x| x.foo } # => false

lambda { 1 } == lambda { 1 } # => true
lambda { 1 + 1 } == lambda { 1 + 1 } # => false

lambda { |x| x } == lambda { |x| x } # => true
lambda { |x| x.foo } == lambda { |x| x.foo } # => false

Proc.new { 1 } == Proc.new { 1 } # => true
Proc.new { 1 + 1 } == Proc.new { 1 + 1 } # => false

Proc.new { |x| x } == Proc.new { |x| x } # => true
Proc.new { |x| x.foo } == Proc.new { |x| x.foo } # => false

Similar also occurs on 1.8.7; on version 1.8.7 (2011-02-18 patchlevel 334), all returned values are (({false})). I also reproduced this behaviour on 1.9.2p136 (2010-12-25 revision 30365) [i686-linux].

Attached is a file which will (({puts})) the values.
=end

proc-equality.rb Magnifier (550 Bytes) Adam Prescott, 04/07/2011 05:07 AM


Related issues

Related to ruby-trunk - Bug #4323: Proc#hash is Ill-Behaved Closed 01/26/2011

Associated revisions

Revision 37929
Added by Koichi Sasada over 1 year ago

add ticket number [Bug #4559]

History

#1 Updated by Koichi Sasada almost 3 years ago

  • Category set to doc
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada

#2 Updated by Koichi Sasada almost 3 years ago

  • Assignee changed from Nobuyoshi Nakada to Yukihiro Matsumoto
  • Priority changed from Normal to Low
  • Target version set to 2.0.0

#3 Updated by Yukihiro Matsumoto almost 3 years ago

I am not satisfied with the current behavior. Two proc objects should
equal either

  • when two proc objects are the same (identical) object (as 1.8 does).
  • or when two proc objects share same body (as documented).

The 1.9 behavior is half-baked, and I think it should be fixed.
I don't say which way to go. It's up to the maintainer (ko1, you).

                        matz.

#4 Updated by Usaku NAKAMURA almost 3 years ago

  • Category changed from doc to core
  • Assignee changed from Yukihiro Matsumoto to Koichi Sasada

#5 Updated by Koichi Sasada almost 2 years ago

Matz (and akr) agreed that Proc#== only see the object_id. I'll change behavior and documents.

#6 Updated by Koichi Sasada over 1 year ago

To solve this ticket, I only need to remove Proc#== from proc.c, isn't it?

#7 Updated by Koichi Sasada over 1 year ago

def test_eq2
b1 = proc { }
b2 = b1.dup
assert(b1 == b2)
end

will be `false'. Is it okay?

#8 Updated by Yukihiro Matsumoto over 1 year ago

@ko1 You've chosen the latter option, so it is natural conclusion.

Matz.

#9 Updated by Koichi Sasada over 1 year ago

(2012/11/28 16:10), matz (Yukihiro Matsumoto) wrote:

@ko1 You've chosen the latter option, so it is natural conclusion.

Okay. I'll delete Proc#==.

--
// SASADA Koichi at atdot dot net

#10 Updated by Koichi Sasada over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37929.
Adam, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


add ticket number [Bug #4559]

#11 Updated by Charles Nutter over 1 year ago

I believe this will be a spec change, albeit a small one. Can we
expect a test or rubyspec to be added for the altered behavior?

  • Charlie

    On Wed, Nov 28, 2012 at 1:10 AM, SASADA Koichi ko1@atdot.net wrote:

    (2012/11/28 16:10), matz (Yukihiro Matsumoto) wrote:

    @ko1 You've chosen the latter option, so it is natural conclusion.

    Okay. I'll delete Proc#==.

    // SASADA Koichi at atdot dot net

#12 Updated by Charles Nutter over 1 year ago

On Mon, Dec 3, 2012 at 1:15 AM, SASADA Koichi ko1@atdot.net wrote:

(2012/12/03 15:26), Charles Oliver Nutter wrote:

I believe this will be a spec change, albeit a small one. Can we
expect a test or rubyspec to be added for the altered behavior?

What is the best way to do with?

I only removed one test from test/ruby/testproc.rb it depends on
previous behavior. (proc
obj == proc_obj.dup).

A similar change for RubySpec may be appropriate. In RubySpec, it
would be by putting a version guard around existing #== expectations
that are no longer valid on 2.0, something like this:

rubyversionis "1.8.6...2.0.0" do
...

Note the exclusive range there. I think it's reasonable to assume that
if Object methods are not customized in Proc, there's no specified
behavior for them other than Object's (or else we'd have to specify
that every Object method in every subclass exhibits the same behavior
as Object).

Making pull request to rubyspec?

That would be fine for now. We can get you commit rights as well.

I need to learn how to write rubyspec to do it.

We'll happily walk you through that or answer any questions.

(and how to make pull request!)

And this too :) Feel free to ping me on IRC whenever I'm around.

  • Charlie

Also available in: Atom PDF