Project

General

Profile

Actions

Bug #22498

closed

Proc#== does not return true for the same lexical code block

Bug #22498: Proc#== does not return true for the same lexical code block

Added by UlyssesZhan (Ulysses Zhan) 15 days ago. Updated 1 day ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127304]

Description

Some context.

The current documentation of Proc#== in Ruby 4 says self == other "returns whether self and other were created from the same code block." However, the following code shows otherwise:

def f = proc { 1 }
f == f # => false

Note that here we have both f returning the code block from the same Ruby code, but they are considered different. A more reliable way to determine the equalness of procs, although only working in CRuby, is

def f = proc { 1 }
RubyVM::InstructionSequence.of(f) == RubyVM::InstructionSequence.of(f) # => true

I don't think the current behavior is necessarily wrong, but the documentation must be misleading if the current behavior is intended.

Updated by nobu (Nobuyoshi Nakada) 14 days ago Actions #1

  • Backport changed from 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED

Updated by nobu (Nobuyoshi Nakada) 14 days ago Actions #2

  • Status changed from Open to Closed

Applied in changeset git|86751a10d06e074103a692d92f1626ec656d9619.


[Bug #22498] [DOC] Clarify Proc#==

Proc is including the binding, not mere code block. State that
Procs with different bindings are not equal.

Updated by k0kubun (Takashi Kokubun) 1 day ago Actions #3 [ruby-core:127516]

  • Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE
Actions

Also available in: PDF Atom