Project

General

Profile

Actions

Bug #12920

closed

Strange NoMethodError in Time.now

Added by kyanagi (Kouhei Yanagita) almost 8 years ago. Updated almost 8 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-11-10 trunk 56692) [x86_64-darwin15]
[ruby-core:78073]

Description

I got a strange NoMethodError in Time.now.

Integer.prepend(Module.new)
module Foo
  refine Integer do
    define_method(:+) { }
  end
end
Time.now
% ~/tmp/ruby-trunk/bin/ruby -v a.rb
ruby 2.4.0dev (2016-11-10 trunk 56692) [x86_64-darwin15]
a.rb:7:in `initialize': undefined method `+' for 1478773005000000000:Integer (NoMethodError)
	from a.rb:7:in `now'
	from a.rb:7:in `<main>'

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #12876: Calling new hangs Ruby when class prepends an empty module and makes initialize method publicClosedko1 (Koichi Sasada)Actions

Updated by akr (Akira Tanaka) almost 8 years ago

The problem is not reproduced with ruby-2.4.0-preview2.
The problem is reproduced with ruby-2.4.0-preview3.

It seems something changed between ruby-2.4.0-preview2 and ruby-2.4.0-preview3.

Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 8 years ago

  • Status changed from Open to Closed

Applied in changeset r56694.


vm_eval.c: fix refined method when prepended

Updated by kyanagi (Kouhei Yanagita) almost 8 years ago

This problem happens with Ruby 2.3.2.

% cat a.rb
Fixnum.prepend(Module.new)
Module.new do
  refine Fixnum do
    define_method(:+) {}
  end
end

Time.now
% ruby -v a.rb
ruby 2.3.2p217 (2016-11-15 revision 56796) [x86_64-darwin16]
a.rb:8:in `initialize': undefined method `+' for 1479217045000000000:Fixnum (NoMethodError)
Did you mean?  +@
	from a.rb:8:in `now'
	from a.rb:8:in `<main>'

Updated by usa (Usaku NAKAMURA) almost 8 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) almost 8 years ago

OMG I've confirmed with the script in the description (prepend and using with Integer) and it cannot reproduce NoMethodError on 2.3.2. But it's because Time.now doesn't use Integer#+ but Fixnum#+.
I've confirmed https://bugs.ruby-lang.org/issues/12920#note-3 was reproducible.
I'm going to backport this and try to understand the impact of this issue.

Actions #6

Updated by usa (Usaku NAKAMURA) almost 8 years ago

  • Related to Bug #12876: Calling new hangs Ruby when class prepends an empty module and makes initialize method public added

Updated by nagachika (Tomoyuki Chikanaga) almost 8 years ago

  • Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: REQUIRED to 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: DONE

ruby_2_3 r56816 merged revision(s) 56694,56698.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0