[Feature #20331] Simplify parser warnings for hash keys duplication and when clause duplication

This commit simplifies warnings for hash keys duplication and when clause duplication,
based on the discussion of https://bugs.ruby-lang.org/issues/20331.
Warnings are reported only when strings are same to ohters.
This commit is contained in:
yui-knk 2024-03-24 08:39:27 +09:00 committed by Yuichiro Kaneko
parent 8066e3ea6e
commit 799e854897
8 changed files with 96 additions and 151 deletions

View file

@ -93,32 +93,6 @@ dvar_defined(ID id, const void *p)
return rb_dvar_defined(id, (const rb_iseq_t *)p);
}
static bool
hash_literal_key_p(VALUE k)
{
switch (OBJ_BUILTIN_TYPE(k)) {
case T_NODE:
return false;
default:
return true;
}
}
static int
literal_cmp(VALUE val, VALUE lit)
{
if (val == lit) return 0;
if (!hash_literal_key_p(val) || !hash_literal_key_p(lit)) return -1;
return rb_iseq_cdhash_cmp(val, lit);
}
static st_index_t
literal_hash(VALUE a)
{
if (!hash_literal_key_p(a)) return (st_index_t)a;
return rb_iseq_cdhash_hash(a);
}
static int
is_usascii_enc(void *enc)
{
@ -611,9 +585,6 @@ static const rb_parser_config_t rb_global_parser_config = {
.local_defined = local_defined,
.dvar_defined = dvar_defined,
.literal_cmp = literal_cmp,
.literal_hash = literal_hash,
.syntax_error_append = syntax_error_append,
.raise = rb_raise,
.syntax_error_new = syntax_error_new,