Project

General

Profile

Actions

Bug #16297

closed

calling undefined allocator by `Class.instance_method(:allocate)`

Added by nobu (Nobuyoshi Nakada) over 4 years ago. Updated about 2 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
[ruby-dev:50856]

Description

For instance, Rational.allocate is undefined.

Rational.allocate #=> undefined method `allocate' for Rational:Class (NoMethodError)

But it can be called by Class.instance_method(:allocate).

Class.instance_method(:allocate).bind_call(Rational) #=> (0/1)
Class.instance_method(:allocate).bind(Rational).call #=> (0/1)

These allocators are defined for Marshal, and undefined as methods.

Updated by usa (Usaku NAKAMURA) about 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED to 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67896 merged revision(s) f72dc407.

Updated by usa (Usaku NAKAMURA) about 3 years ago

usa (Usaku NAKAMURA) wrote in #note-1:

ruby_2_6 r67896 merged revision(s) f72dc407.

note that ruby_2_6 does not have UnboundMethod#bind_call.

Updated by jhawthorn (John Hawthorn) about 2 months ago

I'm not sure if there's a deeper problem this causes, but it is still possible after this patch to call the allocator on a Rational through defining an arbitrary allocate method.

>> def Rational.allocate; end
=> :allocate
>> Class.instance_method(:allocate).bind_call(Rational)
=> (0/1)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0