[ruby-core:127304] [Ruby Bug#22498] Proc#== does not return true for the same lexical code block
Issue #22498 has been reported by UlyssesZhan (Ulysses Zhan). ---------------------------------------- Bug #22498: Proc#== does not return true for the same lexical code block https://bugs.ruby-lang.org/issues/22498 * Author: UlyssesZhan (Ulysses Zhan) * Status: Open * Backport: 3.3: UNKNOWN, 3.4: UNKNOWN, 4.0: UNKNOWN ---------------------------------------- [Some context.](https://bugs.ruby-lang.org/issues/4559#note-13) 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: ```ruby 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 ```ruby 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. -- https://bugs.ruby-lang.org/
Issue #22498 has been updated by k0kubun (Takashi Kokubun). Backport changed from 3.3: REQUIRED, 3.4: REQUIRED, 4.0: REQUIRED to 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ruby_4_0 commit:c239ebbf76484aca86f8b7f6ab0f3f3ac15fba22 merged revision(s) commit:86751a10d06e074103a692d92f1626ec656d9619. ---------------------------------------- Bug #22498: Proc#== does not return true for the same lexical code block https://bugs.ruby-lang.org/issues/22498#change-119984 * Author: UlyssesZhan (Ulysses Zhan) * Status: Closed * Backport: 3.3: REQUIRED, 3.4: REQUIRED, 4.0: DONE ---------------------------------------- [Some context.](https://bugs.ruby-lang.org/issues/4559#note-13) 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: ```ruby 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 ```ruby 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. -- https://bugs.ruby-lang.org/
participants (2)
-
k0kubun (Takashi Kokubun) -
UlyssesZhan (Ulysses Zhan)