mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Avoid improper optimization of case statements mixed integer/rational/complex
Fixes [Bug #17857]
This commit is contained in:
parent
11ae581a4a
commit
9ce29c94d8
Notes:
git
2021-05-13 11:30:25 +09:00
2 changed files with 15 additions and 0 deletions
|
@ -4537,6 +4537,9 @@ rb_node_case_when_optimizable_literal(const NODE *const node)
|
|||
modf(RFLOAT_VALUE(v), &ival) == 0.0) {
|
||||
return FIXABLE(ival) ? LONG2FIX((long)ival) : rb_dbl2big(ival);
|
||||
}
|
||||
if (RB_TYPE_P(v, T_RATIONAL) || RB_TYPE_P(v, T_COMPLEX)) {
|
||||
return Qundef;
|
||||
}
|
||||
if (SYMBOL_P(v) || rb_obj_is_kind_of(v, rb_cNumeric)) {
|
||||
return v;
|
||||
}
|
||||
|
|
|
@ -102,6 +102,18 @@ class TestCase < Test::Unit::TestCase
|
|||
else
|
||||
assert(false)
|
||||
end
|
||||
case 0
|
||||
when 0r
|
||||
assert(true)
|
||||
else
|
||||
assert(false)
|
||||
end
|
||||
case 0
|
||||
when 0i
|
||||
assert(true)
|
||||
else
|
||||
assert(false)
|
||||
end
|
||||
end
|
||||
|
||||
def test_method_missing
|
||||
|
|
Loading…
Reference in a new issue