Project

General

Profile

Bug #11804

52931 以降、caseでInfinityを使用するとFloatDomainErrorが発生する

Added by yui-knk (Kaneko Yuichiro) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.3.0dev (2015-12-11 trunk 53027) [x86_64-darwin14]
[ruby-dev:49423]

Description

以下のようなケースです。

  def test_infinity
    inf = 1.0/0.0

    result = case inf
             when true then 1
             when false then 0
             else
               inf.to_i rescue nil
             end

    assert_nil result
  end

52930の場合

# Running tests:

Finished tests in 0.136572s, 51.2550 tests/s, 314.8522 assertions/s.
7 tests, 43 assertions, 0 failures, 0 errors, 0 skips

52931の場合

[4/7] TestCase#test_infinity = 0.00 s
  1) Error:
TestCase#test_infinity:
FloatDomainError: Infinity
    ruby/test/ruby/test_case.rb:156:in `test_infinity'

Finished tests in 0.135196s, 51.7767 tests/s, 310.6601 assertions/s.
7 tests, 42 assertions, 0 failures, 1 errors, 0 skips

なおwhenのあとがStringのみのケースだと2.2.3でも例外が発生します。

irb(main):001:0> RUBY_VERSION
=> "2.2.3"
irb(main):002:0>     inf = 1.0/0.0
=> Infinity
irb(main):003:0>
irb(main):004:0*     result = case inf
irb(main):005:1>              when 'str' then :string
irb(main):006:1>              else
irb(main):007:1*                inf.to_i rescue nil
irb(main):008:1>              end
FloatDomainError: Infinity
    from (irb):4
    from .rbenv/versions/2.2.3/bin/irb:11:in `<main>'

Also available in: Atom PDF