Project

General

Profile

Actions

Bug #14552

closed

Kernel#Integer can return a non-Integer object.

Added by mrkn (Kenta Murata) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.6.0dev (2018-02-25 trunk 62575) [x86_64-darwin16]
[ruby-core:85813]

Description

I found a bug that Kernel#Integer returns any non-nil object which is a result of to_int.

obj = Object.new
def obj.to_int
  "str"
end
Integer(obj) #=> "str"
Actions #1

Updated by mrkn (Kenta Murata) over 6 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r62581.


Check the result of to_int in Kernel#Integer

[ruby-core:85813] [Bug #14552]

  • object.c (rb_convert_to_integer):
    Check the result of to_int in Kernel#Integer

  • test/ruby/test_integer.rb: add tests.

  • spec/ruby/core/kernel/Integer_spec.rb: fix examples.

Actions

Also available in: Atom PDF

Like0
Like0