Backport #8238
closed
Prepending any module to DateTime causes infiinite loop when using zone-related methods
Added by mjtko (Mark Titorenko) over 11 years ago.
Updated about 11 years ago.
Description
Prepending a Module to DateTime and then inspecting or trying to use any of the methods associated with the timezone causes what appears to be an inifinite loop.
The following code demonstrates the issue:
require 'date'
DateTime.instance_eval { prepend Module.new }
DateTime.now.offset
A cursory inspection shows that similar results (or lack of!) are yielded from #zone, #hour, #minute etc. though #year, #month and #day appear unaffected:
2.0.0p0 :001 > require 'date'
=> true
2.0.0p0 :002 > DateTime.instance_eval { prepend Module.new }
=> DateTime
2.0.0p0 :003 > d = DateTime.now; nil
=> nil
2.0.0p0 :004 > d.year
=> 2013
2.0.0p0 :005 > d.month
=> 4
2.0.0p0 :006 > d.day
=> 8
2.0.0p0 :007 > d.minute
^C
- Category set to core
- Status changed from Open to Assigned
- Assignee set to nobu (Nobuyoshi Nakada)
- Priority changed from Normal to 5
Hello, Mark
Thank you for your reporting.
I can reproduce it with trunk(r40190) and 2.0.0-dev(patchlevel 120) and wrote smaller reproducive code. It is not an issue of Date/DateTime but method search.
class A
def m
end
private :m
end
class B < A
public :m
prepend Module.new
end
B.new.m
nagachika san
Thank you for your further diagnosis of this problem. A method search issue certainly sounds like it warrants a High priority! I am working around my particular instance of this problem by falling back to an include approach for now.
Cheers,
Mark.
- Target version set to 2.1.0
- Status changed from Assigned to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r42724.
Mark, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
vm_insnhelper.c: fix zsuper in prepended
- vm_insnhelper.c (vm_call_method): a method entry refers the based
class/module, so should search superclass from the origin i-class
where the entry belongs to, to get rid of infinite loop when zsuper
in a prepended class/module. [ruby-core:54105] [Bug #8238]
- Tracker changed from Bug to Backport
- Project changed from Ruby master to Backport200
- Category deleted (
core)
- Status changed from Closed to Assigned
- Assignee changed from nobu (Nobuyoshi Nakada) to nagachika (Tomoyuki Chikanaga)
- Target version deleted (
2.1.0)
- Status changed from Assigned to Closed
This issue was solved with changeset r42726.
Mark, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 42724: [Backport #8238]
* vm_insnhelper.c (vm_call_method): a method entry refers the based
class/module, so should search superclass from the origin i-class
where the entry belongs to, to get rid of infinite loop when zsuper
in a prepended class/module. [ruby-core:54105] [Bug #8238]
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0