diff options
author | 卜部昌平 <[email protected]> | 2021-05-07 10:04:08 +0900 |
---|---|---|
committer | 卜部昌平 <[email protected]> | 2021-05-12 10:30:46 +0900 |
commit | 2bc293e899c9d32dcd794a73de8925c49ecf8f15 (patch) | |
tree | 7579535ee779a40dcbb27df91193768bd92f771a /compile.c | |
parent | 773c690f2553db31a9cc83a037f5449e0c1ea456 (diff) |
cdhash_cmp: can take rational literals
Rational literals are those integers suffixed with `r`. They tend to
be a part of more complex expressions like `123/456r`, but in theory
they can live alone. When such "bare" rational literals are passed to
case-when branch, we have to take care of them. Fixes [Bug #17854]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4469
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -28,6 +28,7 @@ #include "internal/hash.h" #include "internal/numeric.h" #include "internal/object.h" +#include "internal/rational.h" #include "internal/re.h" #include "internal/symbol.h" #include "internal/thread.h" @@ -2004,6 +2005,10 @@ cdhash_cmp(VALUE val, VALUE lit) else if (tlit == T_FLOAT) { return rb_float_cmp(lit, val); } + else if (tlit == T_RATIONAL) { + /* Rational literals don't have fractions. */ + return cdhash_cmp(val, rb_rational_num(lit)); + } else { UNREACHABLE_RETURN(-1); } @@ -2022,6 +2027,8 @@ cdhash_hash(VALUE a) return FIX2LONG(rb_big_hash(a)); case T_FLOAT: return rb_dbl_long_hash(RFLOAT_VALUE(a)); + case T_RATIONAL: + return rb_rational_hash(a); default: UNREACHABLE_RETURN(0); } |