Issue #18236 has been reported by toy (Ivan Kuchin).

----------------------------------------
Bug #18236: Conversion to float not working for object with to_f method
https://bugs.ruby-lang.org/issues/18236

* Author: toy (Ivan Kuchin)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
Following code works on all previous versions (1.8.7-p375, 1.9.3-p551, 2.0.0-p648, 2.1.10, 2.2.10, 2.4.10, 2.5.9, 2.6.8, 2.7.4), but not on 3.0 versions (3.0.0, 3.0.1, 3.0.2).
``` ruby
class Something
  def to_f
    0.1
  end
end

Thread.new{ }.join(Something.new)
```

On 3.0 it fails with:
```
test.rb:7:in `join': can't convert Something into Float (TypeError)
	from test.rb:7:in `<main>'
```

`Thread#join` uses `rb_to_float` which should handle object with `to_f` method ([1](https://github.com/ruby/ruby/blob/cb4e2cb55a59833fc4f1f6db2f3082d1ffcafc80/include/ruby/internal/intern/object.h#L482-L488), [2](https://github.com/ruby/ruby/blob/cb4e2cb55a59833fc4f1f6db2f3082d1ffcafc80/include/ruby/internal/intern/object.h#L424-L443)).

Discovered when digging into a [PR](https://github.com/toy/image_optim/pull/194) submitted by @yahonda



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>