Bug #4401

override :method method breaks Psych

Added by godfat (Lin Jen-Shin) over 1 year ago. Updated 12 months ago.

[ruby-core:35255]
Status:Closed Start date:02/15/2011
Priority:Normal Due date:
Assignee:tenderlovemaking (Aaron Patterson) % Done:

100%

Category:ext
Target version:2.0.0
ruby -v:ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]

Description

I am not sure if this could be considered a bug, but it used to work.
To reproduce it:

ruby -r psych -v -e 'Psych.dump(Struct.new(:method).new)'
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.5.0]
/usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:48:in `method': wrong number of arguments(1 for 0) (ArgumentError)
        from /usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:48:in `accept'
        from /usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:36:in `<<'
        from /usr/local/Cellar/ruby/1.9.2-p136/lib/ruby/1.9.1/psych.rb:165:in `dump'
        from -e:1:in `<main>'

I don't have a good idea how to fix it,
but here's some demonstration:

https://github.com/godfat/ruby/commit/f4e0e8f781b05c767ad2472a43a4ed0727a75708
https://github.com/godfat/ruby/commit/c7a6cf975d88828c2ed27d253f41c480f9b66ad6

Patches attached as well, the same as above two commits.
I think they are against r30885.

Many thanks!

p.s. this issue was found in delayed_job's:
class PerformableMethod < Struct.new(:object, :method, :args)

0001-psych-visitors-yaml_tree.rb-use-public_method-instea.patch (2.8 kB) godfat (Lin Jen-Shin), 02/16/2011 12:12 am

0002-psych-visitors-yaml_tree.rb-skip-warning-when-excpt-.patch (2.7 kB) godfat (Lin Jen-Shin), 02/16/2011 12:12 am

History

Updated by godfat (Lin Jen-Shin) over 1 year ago

The other way, might be:

    Object.instance_method(:method).bind(target).call(:to_yaml).source_location.first

Either way is fine for me.

Updated by headius (Charles Nutter) over 1 year ago

Fails the same in JRuby (we just reuse Psych's .rb code): http://jira.codehaus.org/browse/JRUBY-5520

Updated by shyouhei (Shyouhei Urabe) about 1 year ago

  • Status changed from Open to Assigned

Updated by ko1 (Koichi Sasada) 12 months ago

Aaron, how about it?

Updated by tenderlovemaking (Aaron Patterson) 12 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100
This was fixed in r31075. I'm not sure why redmine didn't automatically close.

Also available in: Atom PDF