mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Warn more duplicate literal hash keys
Following non-special_const literals: * T_REGEXP
This commit is contained in:
parent
37eb5e7439
commit
9f3888d6a3
Notes:
git
2021-06-03 15:11:39 +09:00
5 changed files with 10 additions and 3 deletions
|
@ -2011,6 +2011,9 @@ rb_iseq_cdhash_cmp(VALUE val, VALUE lit)
|
|||
const struct RComplex *comp2 = RCOMPLEX(lit);
|
||||
return rb_iseq_cdhash_cmp(comp1->real, comp2->real) || rb_iseq_cdhash_cmp(comp1->imag, comp2->imag);
|
||||
}
|
||||
else if (tlit == T_REGEXP) {
|
||||
return rb_reg_equal(val, lit) ? 0 : -1;
|
||||
}
|
||||
else {
|
||||
UNREACHABLE_RETURN(-1);
|
||||
}
|
||||
|
@ -2033,6 +2036,8 @@ rb_iseq_cdhash_hash(VALUE a)
|
|||
return rb_rational_hash(a);
|
||||
case T_COMPLEX:
|
||||
return rb_complex_hash(a);
|
||||
case T_REGEXP:
|
||||
return NUM2LONG(rb_reg_hash(a));
|
||||
default:
|
||||
UNREACHABLE_RETURN(0);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ VALUE rb_reg_check_preprocess(VALUE);
|
|||
long rb_reg_search0(VALUE, VALUE, long, int, int);
|
||||
VALUE rb_reg_match_p(VALUE re, VALUE str, long pos);
|
||||
bool rb_reg_start_with_p(VALUE re, VALUE str);
|
||||
VALUE rb_reg_hash(VALUE re);
|
||||
VALUE rb_reg_equal(VALUE re1, VALUE re2);
|
||||
void rb_backref_set_string(VALUE string, long pos, long len);
|
||||
void rb_match_unbusy(VALUE);
|
||||
int rb_match_count(VALUE match);
|
||||
|
|
1
parse.y
1
parse.y
|
@ -12189,7 +12189,6 @@ hash_literal_key_p(VALUE k)
|
|||
{
|
||||
switch (OBJ_BUILTIN_TYPE(k)) {
|
||||
case T_NODE:
|
||||
case T_REGEXP:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
|
|
4
re.c
4
re.c
|
@ -3009,7 +3009,7 @@ static st_index_t reg_hash(VALUE re);
|
|||
* See also Object#hash.
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
VALUE
|
||||
rb_reg_hash(VALUE re)
|
||||
{
|
||||
st_index_t hashval = reg_hash(re);
|
||||
|
@ -3043,7 +3043,7 @@ reg_hash(VALUE re)
|
|||
* /abc/u == /abc/n #=> false
|
||||
*/
|
||||
|
||||
static VALUE
|
||||
VALUE
|
||||
rb_reg_equal(VALUE re1, VALUE re2)
|
||||
{
|
||||
if (re1 == re2) return Qtrue;
|
||||
|
|
|
@ -484,6 +484,7 @@ class TestRubyLiteral < Test::Unit::TestCase
|
|||
'1.0r',
|
||||
'1.0i',
|
||||
'1.72723e-77',
|
||||
'//',
|
||||
) do |key|
|
||||
assert_warning(/key #{Regexp.quote(eval(key).inspect)} is duplicated/) do
|
||||
eval("{#{key} => :bar, #{key} => :foo}")
|
||||
|
|
Loading…
Add table
Reference in a new issue