Projects

Ticket #571 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

#respond_to? should return false for unimplemented methods

Reported by: honglilai@… Owned by: lsansonetti@…
Priority: blocker Milestone: MacRuby 0.6
Component: MacRuby Keywords:
Cc:

Description

MRI >= 1.9.2's #respond_to? method now returns false for unimplemented methods. By "unimplemented" I mean methods which are #defined as rb_f_notimplement in the MRI 1.9 source code. rb_f_notimplemented is a method which raises NotImplementedErrror.

An example of this is Process.fork, implemented on MRI 1.9 as rb_f_fork. The #fork method is defined on all platforms, even on platforms where fork is not actually supported (i.e. rb_f_fork is #defined to rb_f_notimplemented). However Process.respond_to?(:fork) now returns false instead of true on these platforms.

MacRuby should follow this behavior.

Attachments

bug_571_unavailable_imp_test_for_rb_f_not_implement.diff Download (1.1 KB) - added by maxime.curioni@… 2 years ago.

Change History

follow-up: ↓ 2   Changed 2 years ago by lsansonetti@…

Let's follow MRI here and register a common implementation symbol for unimplemented methods, then refresh the UNAVAILABLE_IMP macro to also check for this symbol.

Changed 2 years ago by maxime.curioni@…

in reply to: ↑ 1   Changed 2 years ago by maxime.curioni@…

Replying to lsansonetti@…:

Let's follow MRI here and register a common implementation symbol for unimplemented methods, then refresh the UNAVAILABLE_IMP macro to also check for this symbol.

I followed Laurent's recommendation and added the test (whether the current method is equal to rb_f_notimplement) to the UNAVAILABLE_IMP macro.

To test it, I updated spec/frozen/core/process/fork_spec.rb, to skip the old spec. I am new to MacRuby so I don't know if changing specs in the frozen directory or specifying specs just for our implementation is the way to go. Please share any criticism/comment you may about my patch.

  Changed 2 years ago by lsansonetti@…

  • status changed from new to closed
  • resolution set to fixed
  • milestone set to MacRuby 0.6

It looks like it was a bad idea to check in UNAVAILABLE_IMP since this macro is used in a few other places, and calling #fork was then triggering method_missing. I added the check in the respond_to? code path in r3397 and merged your spec change in r3398. Everything seems to work :-)

Note: See TracTickets for help on using tickets.