Project

General

Profile

Bug #13817

test/unit breaks Hash

Added by rovf (Ronald Fischer) about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
[ruby-core:82385]

Description

Consider the following program:

#!/usr/bin/env ruby
BEGIN {$VERBOSE = true}
require 'test/unit'
class Hash
  STDERR.puts method_defined?(:<<)
  alias << merge!
  STDERR.puts method_defined?(:<<)
end

In older Ruby versions (1.9.3, 2.3.3), the output of this program was:

false
true

In Ruby 2.4.1, the output is

false
~/work/stash/vp5/src/test/test_xx.rb:6: warning: method redefined; discarding old <<
true

Please note:

  1. The warning occurs, even though method_defined? tells us that no << method is in Hash.
  2. The warning disappears, when we do not require test/unit, which suggests that the problem is caused by test/unit
  3. Changing the offending line to alias :<< :merge! does not make any difference

Related issues

Related to Ruby master - Bug #11182: Refinement with alias causes strange behaviorFeedbackActions

Associated revisions

Revision 0db193f9
Added by nobu (Nobuyoshi Nakada) about 2 years ago

vm_method.c: alias warning at refined method

  • vm_method.c (rb_method_entry_make): suppress a warning at refined method which will not be redefined. [ruby-core:82385] [Bug #13817]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59613
Added by nobu (Nobuyoshi Nakada) about 2 years ago

vm_method.c: alias warning at refined method

  • vm_method.c (rb_method_entry_make): suppress a warning at refined method which will not be redefined. [ruby-core:82385] [Bug #13817]

Revision 59613
Added by nobu (Nobuyoshi Nakada) about 2 years ago

vm_method.c: alias warning at refined method

  • vm_method.c (rb_method_entry_make): suppress a warning at refined method which will not be redefined. [ruby-core:82385] [Bug #13817]

Revision 59613
Added by nobu (Nobuyoshi Nakada) about 2 years ago

vm_method.c: alias warning at refined method

  • vm_method.c (rb_method_entry_make): suppress a warning at refined method which will not be redefined. [ruby-core:82385] [Bug #13817]

Revision c7754f58
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 59613: [Backport #13817]

    vm_method.c: alias warning at refined method

    * vm_method.c (rb_method_entry_make): suppress a warning at
      refined method which will not be redefined.
      [ruby-core:82385] [Bug #13817]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@59819 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59819
Added by nagachika (Tomoyuki Chikanaga) about 2 years ago

merge revision(s) 59613: [Backport #13817]

vm_method.c: alias warning at refined method

* vm_method.c (rb_method_entry_make): suppress a warning at
  refined method which will not be redefined.
  [ruby-core:82385] [Bug #13817]

Revision ddda4baf
Added by usa (Usaku NAKAMURA) about 2 years ago

merge revision(s) 59613: [Backport #13817]

    vm_method.c: alias warning at refined method

    * vm_method.c (rb_method_entry_make): suppress a warning at
      refined method which will not be redefined.
      [ruby-core:82385] [Bug #13817]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59880
Added by usa (Usaku NAKAMURA) about 2 years ago

merge revision(s) 59613: [Backport #13817]

vm_method.c: alias warning at refined method

* vm_method.c (rb_method_entry_make): suppress a warning at
  refined method which will not be redefined.
  [ruby-core:82385] [Bug #13817]

History

Updated by kou (Kouhei Sutou) about 2 years ago

  • Assignee set to ktsj (Kazuki Tsujimoto)
  • Status changed from Open to Third Party's Issue

It's not caused by test-unit. It's caused by power_assert.

Please report it to https://github.com/k-tsj/power_assert/issues/new with the following script:

#!/usr/bin/env ruby
$VERBOSE = true
require 'power_assert/enable_tracepoint_events'
class Hash
  STDERR.puts method_defined?(:<<)
  alias << merge!
  STDERR.puts method_defined?(:<<)
end
#4

Updated by wanabe (_ wanabe) about 2 years ago

  • Related to Bug #11182: Refinement with alias causes strange behavior added

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
  • Status changed from Third Party's Issue to Open
  • Description updated (diff)

It's a ruby's bug.
"old <<" means a refined method, but it is not redefined actually.

class C
  def t; :t; end
  def f; :f; end
end

module M
  refine C do
    alias foo t
  end
end

class C
  alias foo f
end

using M
p C.new.foo #=> :t
#6

Updated by nobu (Nobuyoshi Nakada) about 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59613.


vm_method.c: alias warning at refined method

  • vm_method.c (rb_method_entry_make): suppress a warning at refined method which will not be redefined. [ruby-core:82385] [Bug #13817]

Updated by nagachika (Tomoyuki Chikanaga) about 2 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r59819 merged revision(s) 59613.

Updated by usa (Usaku NAKAMURA) about 2 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_3 r59880 merged revision(s) 59613.

Also available in: Atom PDF