From 2bc293e899c9d32dcd794a73de8925c49ecf8f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?= Date: Fri, 7 May 2021 10:04:08 +0900 Subject: 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] --- rational.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'rational.c') diff --git a/rational.c b/rational.c index c7437df86f..846e8bd586 100644 --- a/rational.c +++ b/rational.c @@ -1742,8 +1742,8 @@ nurat_rationalize(int argc, VALUE *argv, VALUE self) } /* :nodoc: */ -static VALUE -nurat_hash(VALUE self) +st_index_t +rb_rational_hash(VALUE self) { st_index_t v, h[2]; VALUE n; @@ -1754,9 +1754,16 @@ nurat_hash(VALUE self) n = rb_hash(dat->den); h[1] = NUM2LONG(n); v = rb_memhash(h, sizeof(h)); - return ST2FIX(v); + return v; +} + +static VALUE +nurat_hash(VALUE self) +{ + return ST2FIX(rb_rational_hash(self)); } + static VALUE f_format(VALUE self, VALUE (*func)(VALUE)) { -- cgit v1.2.1