Project

General

Profile

Actions

Bug #4559

closed

Proc#== does not match the documented behaviour

Added by aprescott (Adam Prescott) almost 13 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
Backport:
[ruby-core:35632]

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


Files

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

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4323: Proc#hash is Ill-BehavedClosedmatz (Yukihiro Matsumoto)01/26/2011Actions

Updated by ko1 (Koichi Sasada) almost 13 years ago

  • Category set to doc
  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)
Actions #2

Updated by ko1 (Koichi Sasada) almost 13 years ago

  • Assignee changed from nobu (Nobuyoshi Nakada) to matz (Yukihiro Matsumoto)
  • Priority changed from Normal to 3
  • Target version set to 2.0.0

Updated by matz (Yukihiro Matsumoto) almost 13 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.

Updated by usa (Usaku NAKAMURA) almost 13 years ago

  • Category changed from doc to core
  • Assignee changed from matz (Yukihiro Matsumoto) to ko1 (Koichi Sasada)

Updated by ko1 (Koichi Sasada) over 11 years ago

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

Updated by ko1 (Koichi Sasada) over 11 years ago

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

Updated by ko1 (Koichi Sasada) over 11 years ago

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

will be `false'. Is it okay?

Updated by matz (Yukihiro Matsumoto) over 11 years ago

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

Matz.

Updated by ko1 (Koichi Sasada) over 11 years ago

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

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

Okay. I'll delete Proc#==.

--
// SASADA Koichi at atdot dot net

Actions #10

Updated by ko1 (Koichi Sasada) over 11 years 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]

Updated by headius (Charles Nutter) over 11 years 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 wrote:

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

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

Okay. I'll delete Proc#==.

--
// SASADA Koichi at atdot dot net

Updated by headius (Charles Nutter) over 11 years ago

On Mon, Dec 3, 2012 at 1:15 AM, SASADA Koichi 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/test_proc.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:

ruby_version_is "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
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0