Forum: Ruby-core [Ruby 1.9 - Bug #4559][Open] Proc#== does not match the documented behaviour

Posted by Adam Prescott (Guest)
on 2011-04-06 22:08
(Received via mailing list)
Issue #4559 has been reported by Adam Prescott.

----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
http://redmine.ruby-lang.org/issues/4559

Author: Adam Prescott
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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.
Posted by Koichi Sasada (Guest)
on 2011-06-11 10:06
(Received via mailing list)
Issue #4559 has been updated by Koichi Sasada.

Category set to DOC
Status changed from Open to Assigned
Assignee set to Nobuyoshi Nakada


----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
http://redmine.ruby-lang.org/issues/4559

Author: Adam Prescott
Status: Assigned
Priority: Normal
Assignee: Nobuyoshi Nakada
Category: DOC
Target version:
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by Koichi Sasada (Guest)
on 2011-06-13 15:44
(Received via mailing list)
Issue #4559 has been updated by Koichi Sasada.

Assignee changed from Nobuyoshi Nakada to Yukihiro Matsumoto
Priority changed from Normal to Low
Target version set to 1.9.x


----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
http://redmine.ruby-lang.org/issues/4559

Author: Adam Prescott
Status: Assigned
Priority: Low
Assignee: Yukihiro Matsumoto
Category: DOC
Target version: 1.9.x
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by Yukihiro Matsumoto (Guest)
on 2011-06-13 17:26
(Received via mailing list)
Issue #4559 has been updated by Yukihiro Matsumoto.


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.

----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
http://redmine.ruby-lang.org/issues/4559

Author: Adam Prescott
Status: Assigned
Priority: Low
Assignee: Yukihiro Matsumoto
Category: DOC
Target version: 1.9.x
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by Usaku NAKAMURA (Guest)
on 2011-06-13 17:34
(Received via mailing list)
Issue #4559 has been updated by Usaku NAKAMURA.

Category changed from DOC to core
Assignee changed from Yukihiro Matsumoto to Koichi Sasada


----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
http://redmine.ruby-lang.org/issues/4559

Author: Adam Prescott
Status: Assigned
Priority: Low
Assignee: Koichi Sasada
Category: core
Target version: 1.9.x
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by ko1 (Koichi Sasada) (Guest)
on 2012-07-14 07:36
(Received via mailing list)
Issue #4559 has been updated by ko1 (Koichi Sasada).


Matz (and akr) agreed that Proc#== only see the object_id.  I'll change 
behavior and documents.
----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
https://bugs.ruby-lang.org/issues/4559#change-28029

Author: aprescott (Adam Prescott)
Status: Assigned
Priority: Low
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by ko1 (Koichi Sasada) (Guest)
on 2012-09-22 02:40
(Received via mailing list)
Issue #4559 has been updated by ko1 (Koichi Sasada).


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

----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
https://bugs.ruby-lang.org/issues/4559#change-29659

Author: aprescott (Adam Prescott)
Status: Assigned
Priority: Low
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by ko1 (Koichi Sasada) (Guest)
on 2012-11-26 10:55
(Received via mailing list)
Issue #4559 has been updated by ko1 (Koichi Sasada).



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

will be `false'.  Is it okay?

----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
https://bugs.ruby-lang.org/issues/4559#change-33948

Author: aprescott (Adam Prescott)
Status: Assigned
Priority: Low
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by matz (Yukihiro Matsumoto) (Guest)
on 2012-11-28 08:10
(Received via mailing list)
Issue #4559 has been updated by matz (Yukihiro Matsumoto).


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

Matz.
----------------------------------------
Bug #4559: Proc#== does not match the documented behaviour
https://bugs.ruby-lang.org/issues/4559#change-34073

Author: aprescott (Adam Prescott)
Status: Assigned
Priority: Low
Assignee: ko1 (Koichi Sasada)
Category: core
Target version: 2.0.0
ruby -v: ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]


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

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
Posted by SASADA Koichi (Guest)
on 2012-11-28 08:11
(Received via mailing list)
(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#==.
Posted by Charles Nutter (headius)
on 2012-12-03 07:26
(Received via mailing list)
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
Posted by SASADA Koichi (Guest)
on 2012-12-03 08:15
(Received via mailing list)
(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).

Making pull request to rubyspec?
I need to learn how to write rubyspec to do it.
(and how to make pull request!)
Posted by Charles Nutter (headius)
on 2012-12-03 08:28
(Received via mailing list)
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/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
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.